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

Geting can't call range for one particular method. Below is my code. -----------------
#require 5.008; use diagnostics; use warnings; use strict; use Win32::OLE; use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; main(); sub main { my $cnt=1; my $ex = Win32::OLE->new('Excel.Application'); my $workbook1= $ex->Workbooks->Open('D:\\TradedBondFiles\\IN\\Trad +edBondFile.xls',3) || die "Something went wrong: " ; my $sheet1= $workbook1->WorkSheets(1); our $sheet2=$workbook1->WorkSheets(2); $workbook1->Worksheets(1)->Range("B3:B1000")->Copy; $workbook1->Worksheets(2)->Range("A1:A1000")->PasteSpecial; $workbook1->Worksheets(1)->Range("J3:J1000")->Copy; $workbook1->Worksheets(2)->Range("B1:B1000")->PasteSpecial; $workbook1->Worksheets(1)->Range("G3:G1000")->Copy; $workbook1->Worksheets(2)->Range("C1:C1000")->PasteSpecial; $workbook1->Worksheets(1)->Range("K3:K1000")->Copy; $workbook1->Worksheets(2)->Range("D1:D1000")->PasteSpecial; $workbook1->Worksheets(1)->Range("M3:M1000")->Copy; $workbook1->Worksheets(2)->Range("E1:E1000")->PasteSpecial; $workbook1->Worksheets(1)->Range("H3:H1000")->Copy; $workbook1->Worksheets(2)->Range("F1:F1000")->PasteSpecial; $workbook1->Worksheets(1)->Range("F3:F1000")->Copy; $workbook1->Worksheets(2)->Range("G1:G1000")->PasteSpecial; $workbook1->Worksheets(1)->Range("A3:A1000")->Copy; $workbook1->Worksheets(2)->Range("H1:H1000")->PasteSpecial; $sheet2->Range("C1:C1000")->{NumberFormat} = "dd-mon-yy"; $ex-> {DisplayAlerts} = 0; $sheet2->SaveAs ({Filename => "D:\\TradedBondFiles\\OUT\\TradedBon +dFile.csv",FileFormat =>xlCSV}); $cnt = $cnt+1; $workbook1->Close(); $ex->Quit(); }

Replies are listed 'Best First'.
Re: Can't call method "Range".. a call for politeness
by Discipulus (Canon) on Nov 11, 2015 at 12:09 UTC
    It seems that you removed entirely the root node of your question: this would be very unpolite behaviour: non one can help you further if non code is there, nor the original question.

    If you ask for help you MUST be polite and present the code well formatted and do meaning questions. I've told you this in the chat but i repeat here again.

    Put more effort in next questions and you'll see that answers will be more usefull. search this site for the basic debugging checklist. Inspect vars named in the error Perl reports, a bare print statement is enough most of the times.

    L*

    UPDATE 12 Nov 2015: it seems you restored again the (original?) content of your post. putting an update like this one is considered polite to others when you add something. if you want delete some content you can use <strike> ... </strike> tags and explain why you are modifying your post. sic
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Can't call method "Range" on an undefined value at line 16
by Anonymous Monk on Nov 11, 2015 at 07:32 UTC

    Hi abhishek1990

    its because  $workbook1->Worksheets(1) returns undef

    Now you just have to find out why that is :D

      that is required as 'm pasting the values in sheet 2. so i have defined the sheet2.

        that is required as 'm pasting the values in sheet 2. so i have defined the sheet2.

        what? This is the sequence

        Q: I get error...

        A: Its because...

        ?: that is required

        You're getting an error, you may require that it simply works, but you're getting an error ... now you have to figure out why, wrong API call, wrong version of office, something else ... Worksheets(1) is returning undef, you have to figure out why,

        I don't have excel