Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
O.K. Rockhammer; Another lesson.
Wb is the reference to the workbook which was activated at the time of selecting Print. it is carried forward so that it can be used in your code. Now when you have Application type events, the event will be called if you have the workbook open and then open another workbook and decide to print something from the other workbook. This could cause you real problems if you do not address the situation in the code. The following code is a demonstration to show what happens and how to handle the situation with an if statement. You probably won't need the Else; I only put that in for demo purposes. Amend your code in your workbook and then create another workbook and print from it and observe what happens and I am sure you will work out what I mean. Private Sub app_WorkbookBeforePrint(ByVal Wb As Workbook, Cancel As Boolean) Dim WS As Worksheet Dim wsSel Cancel = True 'Cancel print during testing. MsgBox "app_WorkbookBeforePrint called from " & Wb.Name If Wb.Name = "Test Multi Sheet Print.xls" Then MsgBox "Correct workbook. Therefore process" Set wsSel = ActiveWindow.SelectedSheets For Each WS In ActiveWindow.SelectedSheets 'Note:- Next code line uses 'Now' for date and time WS.PageSetup.CenterFooter = "&8data as of " _ & Format(Now, "yyyy-mm-dd hh:mm:ss") _ & Chr(13) & "Page &P of &N" Next WS wsSel.Select Else MsgBox "Processing skipped for workbook " & Wb.Name End If End Sub Regards, OssieMac |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Print selected worksheets in multiple workbooks? | Excel Discussion (Misc queries) | |||
Print selected pages from multiple worksheets | Excel Discussion (Misc queries) | |||
Printing single pages from multiple worksheets in a single print job | Excel Discussion (Misc queries) | |||
How do I print a workbook in but only print selected worksheets? | Excel Discussion (Misc queries) | |||
Printing Selected Worksheets | Excel Programming |