Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

OLE Excel 2003 moving sheets

by gibsonca (Beadle)
on Jan 25, 2010 at 17:33 UTC ( #819548=perlquestion: print w/replies, xml ) Need Help??
gibsonca has asked for the wisdom of the Perl Monks concerning the following question:

I want to move (not copy) an excel sheet(3) to the first sheet(1). May I have a suggestion how to do this? This would have the effect of making the old first sheet 2nd. thanks

Replies are listed 'Best First'.
Re: OLE Excel 2003 moving sheets
by davies (Parson) on Jan 25, 2010 at 18:17 UTC
    use strict; use diagnostics; use warnings; use Win32::OLE; my $xl = Win32::OLE->new('Excel.Application'); $xl->{Visible} = 1; my $wb = $xl->Workbooks->Add; my $nSheets = $wb->Sheets->Count; if ($nSheets < 3) { for ($nSheets .. 2) { $wb->Sheets->Add({After=>$wb->Sheets($wb->Sheets->Count)}); } } $wb->Sheets(3)->Move({Before=>$wb->Sheets(1)});
    I think it's the last line you'll be interested in. I had to write the rest to test it (my default is one sheet), so it's all there for posterity. Watch for the differences between (brackets) and {braces} if you're peeking and poking.


    John Davies
Re: OLE Excel 2003 moving sheets
by xyzzy (Pilgrim) on Jan 25, 2010 at 17:57 UTC
    You can use the VBA help browser to find the method of the Worksheet object. Or if you have ActiveState then you can try their OLE browser. The perl code will usually be the same except for translating . into ->

    $,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
    Happy, sober, smart: pick two.
Re: OLE Excel 2003 moving sheets
by Anonymous Monk on Jan 25, 2010 at 17:47 UTC
    Um, see if there is a move method?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://819548]
Approved by girarde
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2018-06-20 18:21 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.