VBA Print Settings for all worksheets

Prish

Board Regular
Joined
Mar 30, 2016
Messages
91
What code can be used to set the paper size, orientation, print area based on current region in each worksheet?

I tried to use the following but it fails:
Code:
Dim wSht As Worksheet

For Each wSht In Worksheets
    wSht.Range("A1").CurrentRegion.Select

'printsettings code
Next wSht
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
If you turn on your Macro Recorder and record yourself making the settings the way you like, you should have the code you need to do it.
 
Upvote 0
If you turn on your Macro Recorder and record yourself making the settings the way you like, you should have the code you need to do it.

Thanks Joe, I am familiar with the recorder. However, I am sure you will know the recorder records selected ranges as fixed ranges eg. A1:E356 etc.
I also don't think the recorder records loops, how would it?
I only need to know how to select the current region for all worksheets. I have the print settings code from recording.

for a single sheet I would normally use
Code:
    ActiveCell.CurrentRegion.Select

I cannot figure this out for all sheets.
 
Last edited:
Upvote 0
Why would you select the current region to set print settings?

Try doing what Joe suggested and then post the code here, it should be easy to adapt the generated code to add a loop and set the print area for each sheet individually.
 
Upvote 0
You already have most of the code you need.
I would probably set my current region equal to a range variable, and then just use that range variable in my print settings, i.e.
Code:
Dim wSht As Worksheet
Dim rng As Range


For Each wSht In Worksheets
    wSht.Activate
    Set rng = wSht.Range("A1").CurrentRegion


'printsettings code
    ActiveSheet.PageSetup.PrintArea = rng.Address
Next wSht
 
Upvote 0
You already have most of the code you need.
I would probably set my current region equal to a range variable, and then just use that range variable in my print settings, i.e.

Thanks Joe, that is exactly what I needed.
 
Upvote 0

Forum statistics

Threads
1,216,177
Messages
6,129,323
Members
449,501
Latest member
Amriddin

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