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

I am using Excel 2007 on a Windows XP PC.
I want to have the first 10 rows of a spreadsheet repeated on each page as the spreadsheet is printed.
I created recorded a macro as I did this manually by adding $1:$10 in the rows to repeat at top: of the Sheet tab of the Page Setup window. This gave the following code in the VBA macro.
With ActiveSheet.PageSetup .PrintTitleRows = "$1:$10" .PrintTitleColumns = "" End With ActiveSheet.PageSetup.PrintArea = "" With ActiveSheet.PageSetup .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" .LeftMargin = Application.InchesToPoints(0.590551181102362) .RightMargin = Application.InchesToPoints(0.393700787401575) .TopMargin = Application.InchesToPoints(0.590551181102362) .BottomMargin = Application.InchesToPoints(0.393700787401575) .HeaderMargin = Application.InchesToPoints(0.31496062992126) .FooterMargin = Application.InchesToPoints(0.31496062992126) .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 = False .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
The print preview showed that I had the title rows that I wanted.
I then added the following Perl lines
$sheet->PageSetup -> {PrintTitleRows} = "$1:$10"; $sheet->PageSetup -> {PrintTitleColumns} = "";
However after using these lines I found that nothing was ‘written’ in the Sheet tab entry box and I did not get the title rows on the 2nd and subsequent pages.
What do I have to do to get the title rows that I want?

Replies are listed 'Best First'.
Re: Getting title rows in Excel
by jmcnamara (Monsignor) on Mar 04, 2011 at 12:27 UTC
    Your Perl code is interpolating "$1:$10". You should single quote it instead.
    $sheet->PageSetup -> {PrintTitleRows} = '$1:$10';

    Using use warnings in your program would have alerted you to that.

    --
    John.

Re: Getting title rows in Excel
by marto (Cardinal) on Mar 04, 2011 at 11:29 UTC
      Yes it did! Thanks for the link