View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default print 2 worksheets from print button?

This code would cause any use of the print option to print the two sheets you
specify in it - has the disadvantages of:
Always printing those two, even if you want to only print one or the other,
or some totally different sheet(s).
Leaving the two sheets selected - so anything the user might change without
first making sure that only a single sheet is selected would appear in the
same cells on both sheets - that could be very problematic.

the code

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Sheets(Array("FirstSheet Name", "Second SheetName")).Select
End Sub

This is a Workbook event processor and must go into the Workbook's code
module. Easy way to get there is to right-click on the Excel Icon
immediately to the left of the word "File" in the main Excel menu and choose
[View Code] from the list that pops up. Copy the code above and paste it
into the module presented to you in the VB Editor. Edit the two worksheet
names in the code to match what your sheets are named. Close the VB Editor
and give it a try.
"fedude" wrote:

Is it possible to intercept the print button with a routine that will print
out the contents of 2 worksheets?

I'm trying to idiot-proof the printing out of the contents of two worksheets
when the user either hits the print button or selects "print" from the file
menu.