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

Hi All, I am facing problem of copying different sheets from excel files to a new summary sheet. I tried with the following code. No luck. Please let me know what mistake i am doing.
sub RFSummary { my @files; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $RFSBook = $Excel->Workbooks->Add || die "Uable to create RFSum +mary file $!"; my $WBook; my $WSheet; my $i = 0; my @sumsheets; @files = $mw->getOpenFile(-initialdir=>"E:\\wi2wi\\Logfiles", -title=>"Select Excel files", -multiple=>1); @sumsheets = ("TxP_Summary", "RxPER_Summary"); $RFSBook = $Excel->ActiveWorkbook; my $RFSWSheet = $RFSBook->Worksheets->Add; foreach (@files) { print "$sumsheets[$i]\n"; $WBook = $Excel->Workbooks->Open($_); $WBook->Worksheets($sumsheets[$i])->Copy; $RFSWSheet->Paste; $i++; } $RFSBook->SaveAs("E:\\wi2wi\\Logfiles\\RFSummary"); #$RFSBook->Close; }

Replies are listed 'Best First'.
Re: Copy worksheets to new workbook
by Anonymous Monk on Oct 20, 2008 at 13:33 UTC
    You're not checking for success or failure, not reporting errors