ThisWorkbook BeforePrint

S

Simon Shaw

Hi,

I need to run code after a print job.
I am using
Private Sub Workbook_BeforePrint(Cancel As Boolean)
in ThisWorkbook to execute code prior to printing,
but then I want to run code after printing.

Thanks
Simon
 
S

STEVE BELL

You might look into canceling the print at the beginning of the event.
Than have the code initiate the print (in the code).
Than continue your code to what you want to happen after the print.
 
J

JE McGimpsey

Make sure that if you do this, you disable events prior to printing and
reenable them afterward, or you'll loop until you run out of stack
space. For instance:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
Application.EnableEvents = False
ActiveSheet.PrintOut
Application.EnableEvents = True
'Your code here
End Sub
 
S

Simon Shaw

what if the user was performing a print preview... how do I tell the
difference?
 
J

JE McGimpsey

AFAIK, there's no way to detect the difference between Print and Print
Preview.

However, you can trap the Print Preview command with something like:

CommandBars(1).Controls("File").Controls("Print Preview").OnAction:= _
"MyMacro"

and

Commandbars("Standard").FindControl(id:=109).OnAction = "MyMacro"
 

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

Top