Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default print 2 worksheets from print button?

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default print 2 worksheets from print button?

In the ThisWorbook module there is a before_print event that may be taught
to do this. UNtested

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet12" Then
Sheets("sheet12").PrintOut 'Preview
Sheets("sheet9").PrintOut 'Preview
End If
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"fedude" wrote in message
...
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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default print 2 worksheets from print button?

J,

Bingo. This worked fine. As you and Don suggested, intercepting the
Workbook_BeforePrint event accomplishes exactly what I asked for Thank You!.

You raise a couple of good points.

Maybe a better solution would be to create another custom button for the
toolbar that when pressed prints out the two ranges from the 2 sheets in
question. Is this even possible?

Or is there another way to idiot-proof the printing operation


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

Yes, you can do much of what you have asked regarding a custom button.

Here's what a lot of people, including myself, do with such special things
instead of creating a custom toolbar icon or adding a new menu item:

Start by recording a macro while selecting and printing the two pages.
Use View | Toolbars and bring the Forms toolbar into view. Choose the
command button from that menu and draw one on one of the sheets. Once it's
drawn it will bring up an "Assign Macro?" dialog and offer a default macro
name, don't use that, click on the name of the one you recorded. Edit the
label on the button. You're done!

If you want something a little more colorful, you can use a shape from the
Drawing toolbar in that same fashion: once you've drawn it on the sheet and
added text to it, right-click it and choose Assign Macro and choose the
appropriate macro.

If you do either of these, be sure and remove the Workbook_BeforePrint()
code that we gave you earlier.

"fedude" wrote:

J,

Bingo. This worked fine. As you and Don suggested, intercepting the
Workbook_BeforePrint event accomplishes exactly what I asked for Thank You!.

You raise a couple of good points.

Maybe a better solution would be to create another custom button for the
toolbar that when pressed prints out the two ranges from the 2 sheets in
question. Is this even possible?

Or is there another way to idiot-proof the printing operation


Reply
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
Need to print a workbook but worksheets have diff print areas Angela Steele Excel Discussion (Misc queries) 1 January 17th 08 07:39 PM
print button macro & specific tabs to print Chuck[_3_] Excel Worksheet Functions 2 November 22nd 07 12:21 AM
How do I create a button to print several worksheets in Excel? David Excel Worksheet Functions 1 July 26th 06 07:18 PM
Create command button to print multiple worksheets in a excel file MarcoR Excel Discussion (Misc queries) 3 June 26th 06 07:07 PM
overriding the print button and File/Print Pablo Excel Programming 3 September 11th 03 07:07 PM


All times are GMT +1. The time now is 02:58 AM.

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

About Us

"It's about Microsoft Excel"