Recording a macro for it yields this VB code:
Rows("6:6").Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
wait .. your code actually worked for me (code borrowed mostly from
Using Win32::OLE and Excel - Tips and Tricks).
use strict;
use warnings;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Variant;
use Win32::OLE::NLS qw(:LOCALE :DATE);
$Win32::OLE::Warn = 3; # Die on Errors.
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
$Excel->{Visible} = 1;
my $Book = $Excel->Workbooks->Add();
my $row = 6;
$Excel->Worksheets(1)->HPageBreaks->Add({ Before => $Excel->Worksheets
+(1)->Range("A$row") });
Update: If i add a
$Book->SaveAs('C:\Documents and Settings\David\temp\test.xls'); line in there, then open text.xls, then the page break is NOT there. Hmm.. just crappy Excel behavior??
Update: Yup.
!1 is right -- is really is there if you look hard enough ;) OP's and mine code should both work just fine ...