Using a Macro to print worksheets in a workbook

dwilson38550m

Board Regular
Joined
Nov 21, 2005
Messages
89
I have a workbook with 6 or 7 worksheets in it. I would like to create a macro to print selected ranges within each of the 6 or 7 worksheets. I would then like to create a macro button and put it on the "Instructions" tab on the first page of the workbook so that the user can click the macro button and print all the required pages.

I am unsure how to select the print ranges and specify whether I would like each print over 1 or 2 pages etc. Also, could you please provide a code for me to build a macro from? I am also unsure on the macro where to type in the name of the worksheets I am referring to.

Thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
You can start with this:

Code:
Sub printMe
    Worksheets("Sheet1").Range("C6:D9").PrintOut Copies:=1, Collate:=True
    Worksheets("Sheet1").Range("G10:J16").PrintOut Copies:=1, Collate:=True
    Worksheets("Sheet3").Range("D9:N11").PrintOut Copies:=1, Collate:=True
    Worksheets("Prices").Range("F8:K12").PrintOut Copies:=1, Collate:=True
End Sub

You can assign that to a forms button. Just specify the worksheet name and the range name (much easier with named ranges) to print ranges. You can also set a specific printer or to print to a file. Have a look in the VBA help file, also.

Hope that helps!

EDIT: Fixed code tags
 

dwilson38550m

Board Regular
Joined
Nov 21, 2005
Messages
89
Thanks,

That works - can I specify within the print ranges over how many pages I would like to print (eg for example, if I select "Sheet1" range A1:AA200, but would like this printed over 2 pages so the writing is not too small) - how can I do this?
 

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
You can try using the PageSetup Object to do that.

Code:
    With ActiveSheet.PageSetup
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 2
    End With

Try that and see how it works for you!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,545
Messages
5,838,005
Members
430,525
Latest member
WHall

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top