I have several perl programs which have been running successfully for some time on WinXP using WIN32::OLE, using the interface for both Excel and Word. These programs run on both of our home machines. Recently I started having problems creating the object for Word but only on one of the machines, not the other. The following snippet has worked correctly in the past and still works on the other machine but for some reason it is not returning the object reference.
$word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application'); $mydoc = $word->Documents->Open($xfile);
The Open fails because $word is not defined. Similar code for Excel still works fine.

The boilerplate at the beginning of the program contains:

use Win32; use Win32::OLE; use Win32::OLE "with"; use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Const 'Visual Basic For Applications'; use Win32::OLE::Variant;

It appears that something has changed on this machine but I don't know what to look for. I recently had some problems with my virus checking program for which the "fix" caused some registry problems for I.E. but AFAIK fixing those did not affect anything else.

I have also tried using CreateObject and GetObject but they do not return an object reference either. Is there something in the OLE stuff that gets registered that may have gotten unregistered? Any ideas of what I should look for?

Addendum: When I set Win32::OLE::Warn=2 I get the error message that I have an "Invalid Class String".


In reply to Win32::OLE create object failing by esr

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.