ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide or disable print (https://www.excelbanter.com/excel-programming/291378-hide-disable-print.html)

Gareth[_3_]

Hide or disable print
 
I have a file which will be used in all versions of Excel = '97

I need to hide or disable all print options that the user has (there is a
custom menu with print options which do specific things).

I put the file together in '97 and it works OK with the following but when I
try it on 2000 it hides the wrong icon on the Standard toolbar and the wrong
option in the File menu.

Option Explicit
Private Sub Workbook_Activate()
Application.CommandBars("Standard").Controls(4).De lete
Application.CommandBars("File").Controls(10).Delet e
End Sub

Private Sub Workbook_Deactivate()
Application.CommandBars("Standard").Reset
Application.CommandBars("File").Reset
End Sub

Is there any way to hide or disable print options in all versions with the
same line of code?

Gareth



Ron de Bruin

Hide or disable print
 
Hi Gareth

Why don't you use the beforeprint event not?

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
End Sub

And in your print macro's use

Application.EnableEvents = False
'your print code
Application.EnableEvents = True


Or this

Don't forget the Ctrl-P
See the VBA help for Application.Onkey

You must disable the printpreview also
'109 = printpreview

Sub menuItem_Enabledfalse()
Dim a As Integer
On Error Resume Next
For a = 1 To Application.CommandBars.Count
For Each ctl In CommandBars(a).Controls
Application.CommandBars(a).FindControl(Id:=2521, Recursive:=True).Enabled = False
Next ctl
Next a
End Sub

Sub menuItem_Enabledtrue()
Dim a As Integer
On Error Resume Next
For a = 1 To Application.CommandBars.Count
For Each ctl In CommandBars(a).Controls
Application.CommandBars(a).FindControl(Id:=2521, Recursive:=True).Enabled = True
Next ctl
Next a
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Gareth" wrote in message ...
I have a file which will be used in all versions of Excel = '97

I need to hide or disable all print options that the user has (there is a
custom menu with print options which do specific things).

I put the file together in '97 and it works OK with the following but when I
try it on 2000 it hides the wrong icon on the Standard toolbar and the wrong
option in the File menu.

Option Explicit
Private Sub Workbook_Activate()
Application.CommandBars("Standard").Controls(4).De lete
Application.CommandBars("File").Controls(10).Delet e
End Sub

Private Sub Workbook_Deactivate()
Application.CommandBars("Standard").Reset
Application.CommandBars("File").Reset
End Sub

Is there any way to hide or disable print options in all versions with the
same line of code?

Gareth






All times are GMT +1. The time now is 07:33 AM.

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