iDeviceGuy
iDeviceGuy

Reputation: 993

Invalid or Unqualified Reference

Do I need to put in the sheet name? I need to use this macro across multiple workbooks with similar worksheets but the tab names are different.

Sub pageSetup()
ActiveSheet.pageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(1#)

End Sub

Upvotes: 2

Views: 6168

Answers (1)

brettdj
brettdj

Reputation: 55692

As Tim has not claimed his answer, you could use either of the following two options to either

  • format the ActiveSheet
  • format all WorkSheets in the ActiveWorkBook

ActiveSheet

Sub TimWilliamsPoints()
With ActiveSheet.pageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(1#)
End With
End Sub

All Sheets

Sub TimWilliamsPoints2()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
With ws.pageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(1#)
End With
Next ws
End Sub

Upvotes: 4

Related Questions