I've inherited responsibility for a web app that uses Access for the database and Excel for the reporting (lucky me, I know). Everything has been working fine with Office 2003, however the company has begun pushing out Office 2007 which is now causing issues. So far it looks like Excel 2007 is having issues with one of the reports that is generated.
The report is generated via VBA code in the Access database, the offending line is this:
sht.PageSetup.PrintArea = strPrintArea
strPrintArea in this case had a value of "$C$2:$G$57"
, which looks valid to me. sht
is an Excel Worksheet passed into this function.
However that line will fail withe the following error:
Run-time error '-2147352560(80020010)':
Method 'PrintArea' of object 'PageSetup' failed
I'm stumped as to why the same line of code will work fine with Excel 2003 and fail with Excel 2007. I found Microsoft issued a hotfix around this issue for Excel 2010 (http://support.microsoft.com/kb/2553436) but I haven't found anything similar for Excel 2007.
I'm at a bit of a loss as to where to go next on this. Any help is much appreciated!
Not sure how helpful it'll be but here's the full function where the error is happening:
Sub SetPrintProperty(ByRef sht As Excel.Worksheet, ByRef strPrintArea As String, ByRef douLeftMargin As Double, ByRef douRightMargin As Double, _
ByRef douTopMargin As Double, ByRef douBottomMargin As Double, _
ByRef douHeaderMargin As Double, ByRef douFooterMargin As Double)
'*******************************************************************************************************************
'set the print area for a worksheet
'Arguments:
' sht: the spreadsheet needed to set print area
' strPrintArea: the address of the print area on a spreadsheet
' douLeftMargin: left margin
' douRightMargin: right margin
' douTopMargin: top margin
' douBottomMargin: bottom margin
' douHeaderMargin: header margin
' douFooterMargin: footer margin
'********************************************************************************************************************
sht.PageSetup.PrintArea = strPrintArea
With sht.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
With sht.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Excel.Application.InchesToPoints(douLeftMargin)
.RightMargin = Excel.Application.InchesToPoints(douRightMargin)
.TopMargin = Excel.Application.InchesToPoints(douTopMargin)
.BottomMargin = Excel.Application.InchesToPoints(douBottomMargin)
.HeaderMargin = Excel.Application.InchesToPoints(douHeaderMargin)
.FooterMargin = Excel.Application.InchesToPoints(douFooterMargin)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
' .PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
'.PaperSize = xlPaperLetter
.PaperSize = xlPaperLegal
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With
End Sub
For Each prt In Application.Printers If (prt.DeviceName = "Microsoft XPS Document Writer") Then Set Application.Printer = prt End If Next prt sht.PageSetup.PrintArea = strPrintArea
– Travis