VBA - Print Area Change (from a set range)

slivesay

Board Regular
Joined
Jan 4, 2019
Messages
64
I have an Excel template (wb1) containing VBA to print the set range of a sheet in another workbook (wb2) via a command button. Depending on the options chosen in wb1 will depend on which sheet w/in wb2 prints. The code works, but wk2 contains many sheets (each having their own print area set w/in the wb2 page layout); therefore, it doesn't make sense to have a set print area range w/in wb1 vba coding. It is making some sheets print two pages. What would be the best VBA code to use to have the print area set to either print the sheet using the sheets page layout print area settings or make sure no matter what sheet the code points to print it will print on one page for 100 certainty? Below is the code as it is now and I will also paste what I've gotten to work.

Code:
    ActiveSheet.PageSetup.PrintArea = "$A$1:$V$40" 
             ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
              ActiveWindow.Close 

    [end code]



What I've tried so far was changing the first line to:

[code] 

    ActiveSheet.PageSetup.PrintArea = "" 

    [end code]
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
If you want the printer to use the default print area then do not use the PageSetup.PrintArea statement at all. You can either put and apotrophe ( ' ) in fromnt of the statemen, i.e. comment it out, or you can delete it altogether. The printer will then use the Excel default print area for each sheet.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,626
Messages
6,120,602
Members
448,974
Latest member
ChristineC

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
Back
Top