Hello,
anyone a clue how i can add a new worksheet behind the current last
worksheet in a workbook? How can i specify the position of an excel
worksheet?
use strict;
use warnings;
use Win32::OLE;
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') ||
Win32::OLE->new('Excel.Application', 'Quit');
$Excel->{Visible} = 1;
my $Book = $Excel->Workbooks->Add();
$Excel->{SheetsInNewWorkbook} = 1;
$Book->Worksheets(1)->{NAME} = 'Here when we start';
my $worksheet = $Book->Worksheets->Add();
$worksheet->{NAME} = 'Added first';
$worksheet = $Book->Worksheets->Add();
$worksheet->{NAME} = 'Added second';
# number of worksheets in the workbook
my $sheetcount = $Book->Worksheets->{Count};
my $lastsheet = $Book->Worksheets($sheetcount);
# This one gets put after the last worksheet
# Note that with After => "Thingy"
# the "Thingy" can be any sheet or chart
$worksheet = $Book->Worksheets->Add({After => $lastsheet});
$worksheet->{NAME} = 'Added third';
/me