ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Disable Print button & pulldown menu (https://www.excelbanter.com/excel-programming/438848-disable-print-button-pulldown-menu.html)

Rich

Disable Print button & pulldown menu
 
I'd like to disable the print button in the "standard" toolbar - and maybe
even in the pull-down menu, too - in favor of a custom print button in my
custom toolbar.

I'm not sure how to go about it...

Anyone have any ideas??

TIA.

Peter T

Disable Print button & pulldown menu
 
Have a go with the following but *please* be sure to re-enable when done.

Sub test()
' True enable, False Disable all the Print buttons & shortcut
PrintEnable True '

End Sub


Sub PrintEnable(bEnable As Boolean)
Dim i As Long
Dim cbr As CommandBar
Dim crt As CommandBarControl
Dim cPrt As CommandBarControl

arr = Array(4, 109, 2521)

For Each cbr In CommandBars

For i = 0 To 2
Set cPrt = cbr.FindControl(ID:=arr(i), Recursive:=True)
If Not cPrt Is Nothing Then
cPrt.Enabled = bEnable
' Debug.Print cbr.Name, cPrt.ID, cPrt.Caption
Set cPrt = Nothing
End If
Next
Next

If bEnable Then
Application.OnKey "^p"
Else
Application.OnKey "^p", "DisableCtrlPrint"
End If
End Sub

Sub DisableCtrlPrint()
' MsgBox "This macro does nothing"
End Sub

You might find it surprising to uncomment the debug line to see how in how
many places the print buttons exist.

Regards,
Peter T

"Rich" wrote in message
...
I'd like to disable the print button in the "standard" toolbar - and maybe
even in the pull-down menu, too - in favor of a custom print button in my
custom toolbar.

I'm not sure how to go about it...

Anyone have any ideas??

TIA.




Neptune Dinosaur

Disable Print button & pulldown menu
 
You can harness the Workbook_BeforePrint event to do this (I use it
extensively). In the Workbook_BeforePrint Sub, you set "Cancel = True" to
prevent printing if the value of a Public variable is False. In any other
Subs of yours that invoke a Print, you set that Public variable to True (you
also reset it to False at the end of those Subs). Thus, the print will only
proceed if it has been invoked by a Sub that is called by your print button(s)
--

Time is just the thing that keeps everything from happening all at once


"Rich" wrote:

I'd like to disable the print button in the "standard" toolbar - and maybe
even in the pull-down menu, too - in favor of a custom print button in my
custom toolbar.

I'm not sure how to go about it...

Anyone have any ideas??

TIA.



All times are GMT +1. The time now is 03:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com