title: VBA error on PageSteup.PrintArea when using Excel 2007, works fine in Excel 2003
body: <p>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.</p>
  
  <p>The report is generated via VBA code in the Access database, the offending line is this:</p>
  
  <pre><code>sht.PageSetup.PrintArea = strPrintArea
  </code></pre>
  
  <p>strPrintArea in this case had a value of <code>"$C$2:$G$57"</code>, which looks valid to me.  <code>sht</code> is an Excel Worksheet passed into this function.</p>
  
  <p>However that line will fail withe the following error:</p>
  
  <pre><code>Run-time error '-2147352560(80020010)': 
  Method 'PrintArea' of object 'PageSetup' failed
  </code></pre>
  
  <p>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 (<a href="http://support.microsoft.com/kb/2553436" rel="nofollow">http://support.microsoft.com/kb/2553436</a>) but I haven't found anything similar for Excel 2007.</p>
  
  <p>I'm at a bit of a loss as to where to go next on this.  Any help is much appreciated!</p>
  
  <p>Not sure how helpful it'll be but here's the full function where the error is happening:</p>
  
  <pre><code>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
  </code></pre>