Excel worksheet position

P

peter.tilm

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?

BR/
Peter
 
A

A. Sinan Unur

(e-mail address removed) wrote in @o13g2000cwo.googlegroups.com:
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?

This is not really a Perl question, it is a question about the interface
Excel provides. You can find out about that interface using the "Object
Browser" in the Visual Basic Editor in Excel.

Then, try writing some code to use that interface. If you have problems,
post the code here after having read the posting guidelines.

Sinan
 
B

burlo.stumproot

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
 
P

peter.tilm

Hello!

thanks, it works!
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top