LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default before print macro not printing multiple selected worksheets

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Print selected worksheets in multiple workbooks? T & I Forms Excel Discussion (Misc queries) 1 April 3rd 10 11:52 PM
Print selected pages from multiple worksheets Tigerxxx Excel Discussion (Misc queries) 4 December 29th 07 06:58 PM
Printing single pages from multiple worksheets in a single print job [email protected] Excel Discussion (Misc queries) 2 April 27th 07 06:11 PM
How do I print a workbook in but only print selected worksheets? Karl S. Excel Discussion (Misc queries) 1 August 31st 06 12:34 AM
Printing Selected Worksheets B Baggins Excel Programming 3 September 7th 05 04:35 PM


All times are GMT +1. The time now is 04:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"