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
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

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!
 

Watch MrExcel Video

Forum statistics

Threads
1,118,046
Messages
5,569,852
Members
412,298
Latest member
dietitiann
Top