Set Print Area Dynamically for all worksheets in workbook

Cosmos75

Active Member
Joined
Feb 28, 2002
Messages
359
I can't get this to work? Am a novice at VBA, trying to learn, though. Please help me correct the code below. THANKS!

For Each ws In Worksheets

ws.select
Range(“A1”,Range(“H65536”).End(xlUp).Address).Select

ActiveSheet.PageSetup.PrintArea = Selection

Next ws
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try the following:

For Each ws In Worksheets
ws.Select
ActiveSheet.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address
Next
 
Upvote 0
Al,

Thanks! IT works!

Here's my code. Had it exclude certain worksheets. But it takes a couple of seconds for each worksheet. Is because it's looping though the excluding certain worksheets part? How can I get it to exclude them once and for all and then set print areas for all other sheets??

Also, I want to just set the print area to print on ONE page only.
Can I just use only

.FitToPagesWide = 1
.FitToPagesTall = 1

and exclude the rest?
From .LeftHeader = ""
to .Zoom = False

THANKS!

CODE:
For Each ws In Worksheets
If ws.Name <> "Summary" Then
If ws.Name <> "Conversion Factors" Then
If ws.Name <> "Coatings - All" Then
If ws.Name <> "PivotTable" Then
If ws.Name <> "Calculations" Then
If ws.Name <> "PivotTable-Constituents&Coating" Then
ws.Select
ActiveSheet.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address

With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

End If
End If
End If
End If
End If
End If

Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,733
Members
448,294
Latest member
jmjmjmjmjmjm

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