in reply to Re: excel page breaks???
in thread Help inserting page break in Microsoft Excel using OLE

I apologize for shouting, incorrect phrasing of questions, etc. This is my first jaunt into the monastery, and I am unaccustomed to its procedures. Now that I have read the rules more thoroughly, I shall phrase my question in a more appropriate manner:

Here is my code so far:

use warnings; use strict; use OLE; use Win32::OLE::Const 'Microsoft Excel'; my $excel = CreateObject OLE 'Excel.Application'; my $workbook = $excel -> Workbooks -> Add; my $sheet = $workbook -> Worksheets("Sheet1"); $sheet -> Activate(); $sheet -> Range("6:6") -> Activate();
I want to insert a page break at row 6. Now, the VB code to do this is:
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell

I don't know how to translate this. How do I define "ActiveWindow" and "SelectedSheets?" What parameters do I give "Add()?" I'm sorry if my questions are being phrased incorrectly. I am fairly new to Perl. Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re^3: excel page breaks???
by ikegami (Patriarch) on Mar 01, 2005 at 18:42 UTC

    Given $sheet is
    $workbook->Worksheets("Sheet1")
    or
    $workbook->ActiveSheet

    and given $cell is
    $sheet->Range("6:6")
    or
    $sheet->ActiveCell

    I think it's
    $sheet->HPageBreaks->Add(...)

    For arguments, you could try
    Before => $cell

    I'm really just guessing. MSDN is unusually horrid on this subject.

      Thank you for that advice. My code is now:
      use warnings; use strict; use OLE; use Win32::OLE::Const 'Microsoft Excel'; my $excel = CreateObject OLE 'Excel.Application'; my $workbook = $excel -> Workbooks -> Add; my $sheet = $workbook -> Worksheets("Sheet1"); $sheet -> Activate(); $sheet -> Range("6:6") -> Activate(); $sheet -> HPPageBreaks -> Add(Before => $sheet -> ActiveCell);
      I now receive an error for the last line which reads "Can't call method 'Add' on an undefined value." Did I not read your advice correctly>
        Looks like you have an extra P in HPageBreaks. Try removing that (I'm simply comparing to ikegami's code)
        --------------
        It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs
Re^3: excel page breaks???
by holli (Abbot) on Mar 01, 2005 at 18:28 UTC
    Hollis rule for automating Office No. 1
    1. Start your Office-program.
    2. Activate the makro-recorder.
    3. Do what you want to automate manually.
    4. Stop the makro-recorder.
    5. Inspect the new makro and pick out the relevant code.
    6. Translate that code to perl.


    holli, /regexed monk/
      He has (5). He's asking for help with (6).
Re^3: excel page breaks???
by talexb (Chancellor) on Mar 01, 2005 at 18:14 UTC

    All I can suggest is to look at Spreadsheet::WriteExcel for help. There appears to be a set_h_pagebreaks(@breaks) routine there. If you can get that to work with OLE, terrific.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds