cfree36
Board Regular
- Joined
- Oct 5, 2005
- Messages
- 175
I have the following code however it does not work.
What I want the code to do is go through each worksheet in the file and if cell A2 is >5 then set the Print Area and Page Settings as below.
If I run the code on one sheet without the for each loop the setting work... when I run this code nothing happens.
Any thoughts?
What I want the code to do is go through each worksheet in the file and if cell A2 is >5 then set the Print Area and Page Settings as below.
If I run the code on one sheet without the for each loop the setting work... when I run this code nothing happens.
Any thoughts?
Code:
Sub SetPage()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Select Case ws.Range("A2")
Case Is > 5
ActiveWorkbook.Names.Add Name:="print_area", RefersToR1C1:= _
"=OFFSET(R8C2,0,0,R9C1,R5C1)"
With ActiveSheet.PageSetup
.PrintTitleRows = "$10:$12"
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(1.15)
.BottomMargin = Application.InchesToPoints(1.2)
.Orientation = xlPortrait
.PaperSize = xlPaperLetter
.FitToPagesWide = 1
.FitToPagesTall = False
End With
End Select
Next ws
End Sub