I am trying to develop a function that will automatically set the print area for an excel page. I keep on getting the above error. Any help is appreciated. Tom
The error is highlighted in blue
The error is highlighted in blue
Code:
Public Function SetPrintArea()
Dim rng As Excel.Range
Dim LastRow As Integer
LastRow = ActiveCell.SpecialCells(xlLastCell).Row
[Blue] Set rng = goXl.Range("A1", goXl.UsedRange.SpecialCells(xlLastCell)) [/Blue]
goXl.ActiveSheet.PageSetup.PrintArea = rng
On Error GoTo 1
1: Exit Function
With goXl.ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = goXl.InchesToPoints(0.25)
.RightMargin = goXl.InchesToPoints(0.25)
.TopMargin = goXl.InchesToPoints(0.5)
.BottomMargin = goXl.InchesToPoints(0.5)
.HeaderMargin = goXl.InchesToPoints(0.5)
.FooterMargin = goXl.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Function