On Fri, 08 May 2009, Glenn Linderman wrote:
> On approximately 5/8/2009 12:07 PM, came the following characters from
> the keyboard of Jan Dubois:
> > On Fri, 08 May 2009, Glenn Linderman wrote:
> >> So I open a workbook with macros, and then another workbook with data,
> >> and run A_macro... as follows...
> >>
> >>
> >>        require Win32::OLE;
> >>        require Win32::OLE::Const;
> >>        Win32::OLE::Const->Load('Microsoft Excel');
> >>        $Win32::OLE::Warn = 3;
> >>        $Win32::OLE::Warn = 3;
> >>
> >>        my $Excel = Win32::OLE->new('Excel.Application', 'Quit');
> >>
> >>        my $gl = $Excel->Workbooks->Open(
> >>    $ENV{'APPDATA'} . "\\Microsoft\\Excel\\XLSTART\\gl.xls");
> >>        my $Book = $Excel->Workbooks->Open("SomeData.xls");
> >>        $Excel->Run("gl.xls!A_macro");
> >>        $Book->Close( 0 );
> >>        $gl->Close( 0 );
> >>        $Excel->Close;
> >>
> >> I get an error on the last line:
> >>
> >> Win32::OLE(0.1707) error 0x80020011: "Does not support a collection"
> >>      in METHOD/PROPERTYGET "" at d:\my\perl\src\roster_data.pl line 3352
> >
> > Your sample program above doesn't have over 3000 lines, so the error
> > message and the code don't seem to be related.
> 
> I didn't figure everyone would appreciate the 8863 lines... but the part
> that uses OLE is fully reproduced above.  My reference to the last line,
> $Excel->Close; is line 3352.  Unless Perl is reporting the wrong line
> number, but I have no indication that is the case.

Well, you didn't provide the mapping from line 3352 to $Excel->Close().

I believe the is no Close() method on the Application object, so that would
be throwing the error.  The proper method would be Quit(), but you already
specify this in the Win32::OLE->new() call, so the proper fix should be
to just remove this line.

> > Without "use strict" Win32::OLE will retry some failed method calls
> > as indexing into unnamed collections instead.  That code exists
> > solely for backwards compatibility and is generally not desirable.
> 
> Ah, so maybe because I did a "require Win32::OLE" instead of "use
> Win32::OLE" the strictness doesn't carry over?  Since most runs of the
> program don't need this code, I was trying to avoid the compile time use...

No, it is not the "require".  The issue is that Win32::OLE is checking $^H
at runtime, but $^H is not a lexical variable.  So it's value doesn't
represent the proper state of "use strict" at the time the call was
compiled.

I guess it is time to remove this hack. I only left it in because it
doesn't affect working code; it just sometimes generates confusing error
messages for broken code, but supposedly also fixes scripts dealing with
misguided implementations of OLE Automation objects. But I would expect
these objects to be fixed by now; this hack is over 10 years old.

Cheers,
-Jan

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to