set print area for all sheets using vba

Kaps_mr2

Well-known Member
Joined
Jul 5, 2008
Messages
1,586
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to set the print range on each sheet on my workbook. However the following does not work:-

VBA Code:
For sh = 1 To output_workbook.Sheets.Count

    output_workbook.Sheets(sh).PageSetup.PrintArea = Range("a1:n28").Address
    output_workbook.Sheets(sh).PageSetup.Orientation = xlLandscape
    
    
     
Next sh

thanks
Kapa
 
There is other data on the sheets but I don't want that printed. How can i check if there is other code overwriting my print ranges ?
After the code runs, go to the sheets that are not working properly, and manually check to see what the print range is set to on that sheet.

1696946604063.png
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
i get the error "you've selected a single cell for the print area". Even if i clear the print area i get the same message. This is on all sheets.
 
Upvote 0
i get the error "you've selected a single cell for the print area"
When do you get this error?
When trying to view the print area, or trying to run the VBA code?
 
Upvote 0
I get this error when trying to view the print area (as per your suggestion - which is the sensible thing to do). The code runs with no errors reported.
 
Upvote 0
I get this error when trying to view the print area (as per your suggestion - which is the sensible thing to do). The code runs with no errors reported.
I don't understand why that would be.
I assume that you do not have any hidden, protected, or merged cells on these sheets?
 
Upvote 0
i have just double checked - no hidden, no merged or protected cells. The workbook is created by the macro.
 
Upvote 0
I am at a loss then, without having access to the workbook.
I am afraid I do not have anything else to offer, as I cannot recreate the issue on my end.
 
Upvote 0
If you can upload it to a file sharing site and provide a link to it, I can try downloading it when I am in front of my home computer (not allowed to download things to our work computers).
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

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