in reply to Class names in OLE

Aside from the original question (which I think has been answered quite well) I have a question for you. What happens if your Excel application isn't running? Then the Perl script wouldn't be able to GetActiveObject at all. I'd suggest the following addition:

my $excel = Win32::OLE->GetActiveObject('Excel.Application') or  Win32::OLE->new('Excel.Application');

And of course, check the return code to make sure things went smoothly. But that goes without saying, right? :)

Replies are listed 'Best First'.
Re: Re: Class names in OLE
by Zapawork (Scribe) on Jun 17, 2003 at 20:41 UTC
    Hi,
    I too have been dabling the dark OLE arts recently. You can check to see if the excel object is open, and then if not create a new worksheet.
    On the same note, you could just open the specific file instead of the active object as well.
    $Obj = Win32::OLE->GetObject('c:\somefile.xls');

    However! The article to read would be: here
    Dave -- Saving the world one node at a time
Actually I know it's already open
by Foggy Bottoms (Monk) on Jun 18, 2003 at 09:11 UTC
    Well of course you guys are right - you do have to check whether the excel application is running... or else...
    But actually I check in another package so I know it's there and open. My purpose is to read the currently active document whether saved or not so that's why I use the activeWorkbook property - working with OLE is actually loads of fun !!!
    . Thanks guys and have a nice day.
Re: Re: Class names in OLE
by jdporter (Paladin) on Aug 04, 2003 at 16:53 UTC
    ERROR!

    What you mean is
    my $excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32: +:OLE->new('Excel.Application');
    That is, s/or/||/.

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.