http://qs321.pair.com?node_id=377560

Divinedimepiece has asked for the wisdom of the Perl Monks concerning the following question:

Ok lets see if i can make this clear....i've recorded a macro with some output files....and now i would like to have all the output files appear on one excel sheet...but i want to loop the files in Perl...where it would open the file and run the code from the macro on each one...but is it possible to convert the vba macro into perl ..???..im new to this..so if its not clear..just respond and ask me to clear it up ...
  • Comment on How to convert VBA macro to Windows Perl

Replies are listed 'Best First'.
Re: How to convert VBA macro to Windows Perl
by Grygonos (Chaplain) on Jul 26, 2004 at 20:31 UTC

    And on the 8th day.... Win32::OLE was created and it was good. This module implements OLE objects in perl, so you can do any VBA-capable (and VBA-incapable) action using that module. Read up on it, and use super search to find some good Win32::OLE examples.

    Hope this spurs some discovery,
Re: How to convert VBA macro to Windows Perl
by WhiteBird (Hermit) on Jul 27, 2004 at 02:00 UTC
    Using Win32::OLE, you can actually run the VB macro from the opened file if you want. First specify it as a package

    package MacroName;

    Then you call it in the code like this:

    $YourWin32Object->Run("MacroName");

    The CPAN documentation on Win32::OLE should provide all the detail you need.

      That is very true but I would advise against it. It forces you into supporting multiple platforms. If you do everything in Perl through Win32::OLE, then your developers must know Perl and the OLE package, however if you divide your development into Perl and VBA, you put extra stress on your development by requiring knowledge of both.

      That being said, I know that you're using the same objects, but the programming is done diferently, (and more robustly IHMO) in Perl. I know it sounds like a zealot's way, but I say keep it all in Perl. The manipulation you can perform on your data that you are interacting with is much more robust in Perl than in VBA.

        I agree completely, particularly if the SOPW is using this in any kind of ongoing project.

        Running a VBA macro from the Perl code works adequately if a person is doing a quick run through some documents and data and the end goal is just to get the job done. Anything long term would be worth the extra attention and effort to convert the VBA to Perl.

Re: How to convert VBA macro to Windows Perl
by Mr. Muskrat (Canon) on Jul 27, 2004 at 00:53 UTC
    I wrote a script about 2 years ago that I called VBA 2 Perl. I haven't looked at the code in about 2 years but it should get you pointed in the right direction.