in reply to How to use win32::OLE with multiple versions of Microsoft Office?

To clarify, the only reason I am "Use"ing the Office typelib is to define the mso constants. I was not sure why Dasgar put Microsoft Excel in that line, so I tried this first:
use Win32::OLE::Const 'Microsoft Office .* Object Library'; # mso con +stants
Perl balked, complaining:
No type library matching "Microsoft Office *.0 Object Library" found a +t \winbat\ text2word.pl line 193 Win32::OLE(0.1709): GetOleTypeLibObject() Not a Win32::OLE::TypeLib ob +ject at C: /Perl64/lib/Win32/OLE/Const.pm line 49. Bareword "msoFalse" not allowed while "strict subs" in use at \winbat\ +text2word. pl line 522.
I tried some other incantations, but I either received the No typelib... warning, or no complaint, but no mso... constants, either. Still looking for that magic insight...

Replies are listed 'Best First'.
Re^2: How to use win32::OLE with multiple versions of Microsoft Office?
by dasgar (Priest) on Aug 04, 2011 at 15:29 UTC
    not sure why Dasgar put Microsoft Excel in that line

    I cut and pasted the wrong line. :D

    The problem with your use statement is that you used single quotes instead of double quotes. With single quotes, Perl will not do any interpolation, which would occur with double quotes.

    If you make that one minor change, your code should work.

      Understood. I had used double quotes in the past, but got tired of escaping the period. I tried your version, and I tried this as well:
      use Win32::OLE::Const "Microsoft Office \.* Object Library"; # mso co +nstants
      but no joy. No complaint from Win32::OLE, but no msoFalse defined...

      I forget how I figured out that I needed to put in the exact version number (11.0, 12.0, or 14.0), but that is the only way I have been able to get this to work. I tried to figure out a way to select the right version in a BEGIN-END block, but I lack the perlMonkishness to get that going.

      I can live with one of two solutions (either modify the script for the specific host version of Office -- yuck); or the way it is now (looks ugly as sin, but seems to work; and if multiple versions of office exist, I'll take my chances.

        I don't want to doubt what you're saying, but I am surprised that you're having issues. That line of code has worked for me on multiple systems and across multiple versions of Office (97,2003,2007,2010) on different Windows versions (XP, Vista, Win7, Win2003, Win2008) and different versions of Perl without any problems.

        In fact, I just ran the code below on a Win7 box with ActiveState Perl 5.12.1 and Office 2010 installed. It ran without any errors or complaints.

        use strict; use warnings; use Win32::OLE::Const "Microsoft Office .* Object Library";

        I believe that I'm out of ideas/suggestions at this point. If I can think of anything, I'll come back and post it.