MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Disable Print and save in VBA Excel


Posted by John on January 14, 2002 1:04 PM

How can I block the print and save functions in Excel. I have an invoice program that want to control the printing from my own macro as well as saving. Is there a way to do this and if so how?

Any help would be appreciated,

John


Posted by Jerid on January 14, 2002 1:30 PM

Put this in your ThisWorkbook module, change as needed.

Public bOK2Print As Boolean

Private Sub Workbook_Open()
bOK2Print = False
End Sub

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If bOK2Print = False Then
Cancel = True
End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
End Sub

Sub YourPrintProcedure()
bOK2Print = True
'Your code
bOK2Print = False
End Sub

Jerid