merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

I want to set the page printing option for an Excel spreadsheet (for both Excel 2003 and 2007) to ‘Fit to Page’ so that the spreadsheet is printed on just one page.
In a file of one liners I found the line
$sheet -> PageSetup -> {FitToPagesWide} = 1;
I tried this but it did not work in an Excel 2007 spreadsheet.
Therefore I tried the recommended practice of recording an Excel macro when I used the Fit to Page option – selecting one page for fitting. This gave the following
With ActiveSheet.PageSetup .PrintTitleRows = "" .PrintTitleColumns = "" End With ActiveSheet.PageSetup.PrintArea = "" With ActiveSheet.PageSetup .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" .LeftMargin = Application.InchesToPoints(0.138888888888889) .RightMargin = Application.InchesToPoints(0.277777777777778) .TopMargin = Application.InchesToPoints(6.94444444444444E-02) .BottomMargin = Application.InchesToPoints(0.347222222222222) .HeaderMargin = Application.InchesToPoints(0.3) .FooterMargin = Application.InchesToPoints(0.3) .PrintHeadings = False .PrintGridlines = False .PrintComments = xlPrintNoComments .PrintQuality = -3 .CenterHorizontally = False .CenterVertically = False .Orientation = xlLandscape .Draft = False .PaperSize = xlPaperA4 .FirstPageNumber = xlAutomatic .Order = xlDownThenOver .BlackAndWhite = False .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = 0 .PrintErrors = xlPrintErrorsDisplayed .OddAndEvenPagesHeaderFooter = False .DifferentFirstPageHeaderFooter = False .ScaleWithDocHeaderFooter = True .AlignMarginsHeaderFooter = True .EvenPage.LeftHeader.Text = "" .EvenPage.CenterHeader.Text = "" .EvenPage.RightHeader.Text = "" .EvenPage.LeftFooter.Text = "" .EvenPage.CenterFooter.Text = "" .EvenPage.RightFooter.Text = "" .FirstPage.LeftHeader.Text = "" .FirstPage.CenterHeader.Text = "" .FirstPage.RightHeader.Text = "" .FirstPage.LeftFooter.Text = "" .FirstPage.CenterFooter.Text = "" .FirstPage.RightFooter.Text = "" End With
This included the equivalent of the one liner I found and a lot of other settings as well.
I guessed it might at least some of the other settings so I added the one for paper size. Sadly this still did not work.
Therefore I wondered if any Monk knows what is required to be able to set the Fit to Page option.

Replies are listed 'Best First'.
Re: Excel - Setting Fit to Page Query
by Anonymous Monk on Jun 21, 2010 at 10:59 UTC
      Many thanks - that reference sorted it.
Re: Excel - Setting Fit to Page Query
by davies (Monsignor) on Jun 21, 2010 at 11:12 UTC
    Note the line that says .Zoom = False. That is usually essential to make Fit To Page work. I can't really test this as the computer I'm on has no printer attached, but it's the usual suspect.

    Regards

    John Davies