Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

Comment on OLE Excel 2003 moving sheets
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?
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 davies (Vicar) 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.

    Regards,

    John Davies

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://819548]
Approved by girarde
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (18)
As of 2014-07-10 15:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (212 votes), past polls