Search code examples
perlwinapimoveoleworksheet

perl WIN32::OLE - HowTo move Excel Worksheet (or change position)


In the article List of Perl commands to manipulate Windows Excel with Win32::OLE module it is mentioned how to add an Excel WorkSheet before or after an existing WorkSheet!

I want to move, so change the position of an existing WorkSheet, before or after an other WorkSheet. How can I achieve this? Is it just to replace the add in $Book->Worksheets->Add({After => $workbook->Worksheets($workbook->Worksheets->{Count})}); by move (or copy if I want to copy)?

thank you for your hints! Regards Laurent


Solution

  • You need to use the Worksheet.Move method with the After attribute

    I am not a perl specialist, but the syntax should be:

    $Book->Worksheets("Sheet1")->Move({After => $workbook->Worksheets($workbook->Worksheets("Sheet2"))});