On approximately 5/8/2009 12:54 PM, came the following characters from 
the keyboard of Jan Dubois:
> 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().


It sure looks like I said I get an error on the last line, and 
$Excel->Close() was the last line I pasted... How could have I stated 
that more clearly, for next time?


> 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.


I removed the line, tested the program.  The error didn't recur, and 
Excel didn't stay around.  Thanks for the help.  I'm not a fan of MS, 
Excel, or OLE, preferring to spend time doing useful things, but 
sometimes I try to cut-n-paste some MS stuff into my programs when they 
must interface to some preexisting use... I've read some stuff, but 
error messages like these are totally useless without long experience. 
Poor error messages, and poor error handling are two of my biggest beefs 
with post MS-DOS MS software.  MS-DOS wasn't too bad, but it has only 
gotten worse since.


>>> 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'm glad you understand that!  All I know, is I used strict, so if OLE 
isn't (or can't) detect that properly, then probably it shouldn't try to 
do things based on strict or not... which makes me agree with your next 
idea, but not from the viewpoint of really understanding it.


> 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.


-- 
Glenn -- http://nevcal.com/
===========================
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to