Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have two excel workbooks. I need to insert a sheet from one the book into another, at the end of it. Very similar to "move to end" in excel spreadsheets.

$Book = $excel->workbooks->Open("excl1.xls"); $Book1 = $excel->workbooks->open("excl2.xls"); $sheet1 = $Book->worksheets->Add({After=>$Book1->worksheets(1)});

thanks in advance

Replies are listed 'Best First'.
Re: Move excel sheet into workbook
by Corion (Patriarch) on Mar 09, 2007 at 11:44 UTC

    The code you posted cannot work. (Win32::)OLE cares about the case of the method names. I recorded what you want to do in the macro recorder and got the following code:

    Sheets("Tabelle1").Select Sheets("Tabelle1").Move Before:=Workbooks("Mappe2").Sheets(1)

    It should be fairly able to adapt that to Perl - my untested translation follows:

    my $sheet = $Book->Sheets("Tabelle1"); my $target = $Book1->Sheets( $Book1->Sheets->Count ); $sheet->Move( { After => $target });
    • Cool!! Works! Thanks
Re: Move excel sheet into workbook
by Sagacity (Monk) on Mar 09, 2007 at 15:58 UTC

    Check out this tutorial 153486. It deals with Excel and Win32::OLE.

    I think you may need to use the SheetActivate to provide the correct focus in the excel book, before you add it to the second book.

Re: Move excel sheet into workbook
by Anonymous Monk on Mar 09, 2007 at 11:45 UTC
  • The output i get is only a blank sheet aded in excl1.xls