Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Before Print Event or not? 1

Status
Not open for further replies.

williekay

Technical User
Jun 30, 2003
121
0
0
US
I have an excel document that takes a long time to print. The solution is to open the document in page break view, print the document, and return to normal view. I do this usually with a Macro and the Macro works but this in the ThisWorkbook section does not???

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveWindow.View = xlPageBreakPreview
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.View = xlNormalView
End Sub




Willie
 
I doubt that in this case printing will be faster. Anyway, if you need do pick the 'BeforePrint' event, the logic is:
- cancel current printing action,
- disable events (to avoid recursive events),
- write your own print procedure,
- enable events:
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
  Cancel = True
  Application.EnableEvents = False
  ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
  Application.EnableEvents = True
End Sub
Please note that this event fires when the user previews workbook too. There is no need to change the view to xlPageBreakPreview.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top