overriding the print button and File/Print

  • Thread starter Thread starter Pablo
  • Start date Start date
P

Pablo

Hello:

I have a model that I want to override the ability to print only one
page.

The model has 3 pages and the first page needs to be printed first
always before any of the others.

Can a macro be written that attaches to the model that only allows
printing from a custom print macro? Or, something that when the user
hits the toolbar print button (or File...Print...) the model always
prints the first page too?
 
Pablo,
The code below (place it in the "ThisWorkbook" module) stops all printing
unless the instruction to print comes from one of your printing macros.

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

use something like this to print, put in a normal module
Sub print_this()
Application.EnableEvents = False
'your print macro here
Application.EnableEvents = True
End Sub

--
Paul B
Always backup your data before trying something new
Using Excel 97 & 2000
Please post any response to the newsgroups so others can benefit from it
** remove news from my email address to reply by email **
 
Seeing that there is a way to block basic commands like "Print", what
are the other commands to cancel say "Save"? Is there a list (Web
site?) that shows all the terms/syntax to do this?

For example, using:

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

Can I subsitute "Save" where "print" is and you cannot save a wb?

Also, is there a way to put a password on the workbook that activates
the commands if a pw is entered?
 
Pablo, you can use this to keep the workbook form being saved
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
End Sub

you could use something like this to ask for a password to print, Of course
all this can be disabled if somebody opens the workbook with macros disabled



Private Sub Workbook_BeforePrint(Cancel As Boolean)
'must lock VBA project so you can't see the password in it
'put in this workbook module

Dim myPassword As String

myPassword = InputBox(prompt:="Please enter the password to proceed:", _
Title:="Password is required to print this file.")
'change password to what you want
If myPassword <> "password" Then
MsgBox prompt:="Click OK To Return To The Workbook.", _
Title:="Print Cancelled -- Correct Password Not Entered", _
Buttons:=16
Cancel = True

Else
End If
End Sub
 
Back
Top