PDA

View Full Version : [SOLVED] Disable print



outrider
01-25-2005, 04:18 AM
Is it possible to disable the print icon on the toolbar. I can turn it off in the File menu, but cannot seem to get it right for the toolbar.

Thanks for helping.

Outrider.

Jacob Hilderbrand
01-25-2005, 04:43 AM
Try this code.



Option Explicit

Sub DisablePrint()
Dim CmdBar As CommandBar
Dim CmdCtl As CommandBarControl
For Each CmdBar In CommandBars
Set CmdCtl = CmdBar.FindControl(ID:=2521, recursive:=True)
If Not CmdCtl Is Nothing Then
CmdCtl.Enabled = False
End If
Next CmdBar
Set CmdBar = Nothing
Set CmdCtl = Nothing
End Sub

outrider
01-25-2005, 06:20 AM
Thanks DRJ,

Which bit turns it back on again? :dunno

Jacob Hilderbrand
01-25-2005, 06:24 AM
CmdCtl.Enabled = True

outrider
01-25-2005, 06:36 AM
Thanks again Jake, it works great.

Jacob Hilderbrand
01-25-2005, 06:46 AM
You're Welcome :beerchug:

Take Care

Richie(UK)
01-25-2005, 06:49 AM
... and what if the user of your workbook wants to print from another workbook that they have open?

Generally I would advise against altering the user's Excel setup (hiding menus/menu items, disabling shortcut keys etc - Had you considered Ctrl&P ?). This can be extremely frustrating.

As an alternative, how about using the BeforePrint event in the workbook concerned (Cancel=True)? Just a thought ;)

outrider
01-25-2005, 09:40 AM
Richie,

The users have no other workbooks. It is important to limit their ability to use the file menu or toolbar so that they use a macro that performs many other functions as well as print out the document they need. Ctrl + P is not that much of a problem because most of them do not know about it.

Outrider.

gsouza
01-25-2005, 12:06 PM
You could also put this code in your workbook code.



Private Sub Workbook_BeforePrint(Cancel As Boolean)
MsgBox "Printing is disabled in this workbook."
Cancel = True
End Sub

That way It will only work for this workbook. I hope.