Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^3: Perl r/w Excel with OLE

by dasgar (Deacon)
on Jun 28, 2012 at 17:07 UTC ( #978970=note: print w/ replies, xml ) Need Help??

in reply to Re^2: Perl r/w Excel with OLE
in thread Perl r/w Excel with OLE

The first thing that I personally don't like about the sample code you provided is the attempt to check to see if an instance of Excel is running and to take control of it if there is one. Personally, I prefer my script to open a new instance of Excel so that the script does not interfere with the person/script that is using the other instance. Just a personal preference, but wanted to share my thoughts on that topic.

The sample code's method for closing Excel works fine for Excel 2003 and I believe Excel 2007 too. However, Excel 2010 introduces a few new wrinkles. First, you can specify what version to save the file as (Excel 2007 and older format, Excel 2010 format, etc.). Also, if the format and file extension don't match, Excel likes to prompt the user about what to do. If you have Excel 2010, just manually try saving a new file as different formats and extensions to see what I'm talking about. Also, you can record a macros to see what the VB code looks like to handle some of these "save as" scenarios and convert that to Perl for your script. Just wanted to mention this information in case the OP (or any future reader) is using Excel 2010 (or newer) and finds the information useful.

Note that the visible=1 is great for debugging, but shouldn't be used in a production environment once your script is complete.

Ummm...again I disagree and think that this is a matter of personal preference. Although I typical use the visibility setting as you described, I have a coworker who prefers to leave visible set to 1 so that he can visually watch the script as a method to verify that the script really is running and doing what it is supposed to do. Despite disagreeing with him, I personally am not going to tell someone that they shouldn't be doing that. Basically, just applying the concept of TIMTOWTDI.

Comment on Re^3: Perl r/w Excel with OLE
Re^4: Perl r/w Excel with OLE
by Sinistral (Prior) on Jun 29, 2012 at 16:20 UTC

    Good points. I guess my model of this kind of code is not that it's going to be running on an individual's PC while they are actively doing other things. I was thinking of a headless Windows Server machine that also has MS Office on it, and Perl is doing automation of that Office. If the Win32::OLE code is an alternative to using the built in VBA code of the Office suite, then all of the advice given contrary to mine is absolutely reasonable.

    I have used the visibility setting to see what's happening when debugging, but turning it off when doing a "production" run means that there is no possibility of me interfering with the automated operation (which, for complex multi-setp OLE operations, could happen). I agree it's a personal preference, and that's why I personally prefer it to be invisible once I've got something running properly. :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978970]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-07-31 01:53 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (244 votes), past polls