Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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 the universe expands...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2017-12-13 03:38 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (345 votes). Check out past polls.