http://www.perlmonks.org?node_id=819548

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 (Prior) 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
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?