HELP!!! I keep getting the following error when using the code snippet below:
-------------------------------------------- OLE exception from "Microsoft Office Excel" 'SLOC_Count_C_Sharp_Macro' could not be found. Check the spelling of the file name, and verify the file location is correct. Win32::OLE<0.1707> error 0x800a03ec in METHOD/PROPERTYGET "Run" at test.txt line 27 -------------------------------------------- <<< Code Snippet >>> use Cwd; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; ##my $myPersonalMacros = "D:\\Profiles\\P56739\\Application Data\\Micr +osoft\\Excel\\XLSTART\\Personal.xls"; my $metricsFile = "D:\\Profiles\\P65380\\Deskto\\myMetricsFile.csv"; my $Excel = Win32::OLE->new('Excel.Application') or die "\n\nOops, can +not start Excel\n";; my $Book = $Excel->Workbooks->Open("$metricsFile"); my $Sheet = $Book->Worksheets(1); $Sheet->Activate(); $Excel->Run("Personal.xls!SLOC_Count_C_Sharp_Macro"); $Book->Close; I have everything under the sun to get this to work! It makes no difference; same error returns. I.E. $Excel->Run("SLOC_Count_C_Sharp_Macro"); $Excel->Run("Personal.xls!SLOC_Count_C_Sharp_Macro"); Even... $Excel->Run("$myPersonalMacros!SLOC_Count_C_Sharp_Macro");
Ideally, what I want is to a have a perl script invoke the Win32::OLE macro 'Run' function in newly generated *.csv files that reference predefined macros residing in a Personal.xls file under D:\Profiles\P56739\Application Data\Microsoft\Excel\XLSTART. Manually, I can open a newly generated *.csv on my desktop, go to 'Tools', go to 'Macros', visibly see Personal.xls!SLOC_Count_C_Sharp_Macro in the Macro name box, highlight the name, and 'Run' the macro, which executes correctly every time. But for the like of me, I cannot get Win32::OLE via the 'Run' method to do the same thing. What's going here??? I would appreciate any insight to this silly problem. Thanks. BG

Code tags added by GrandFather


In reply to Re: Using Win32::OLE and Excel - Tips and Tricks by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.