Hide or disable print

  • Thread starter Thread starter Gareth
  • Start date Start date
G

Gareth

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).Delete
Application.CommandBars("File").Controls(10).Delete
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top