#!/usr/bin/perl
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const;
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;
my $filename = 'c:\\book_with_macros.xls';
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $Book = $Excel->Workbooks->Open( $filename );
$Excel->Run("MYMACRONAMEHERE");
$Book->Close;
N.B. The above code is untested.I patched the following together from the examples in the Activestate documentation in the section "Using OLE with Perl", under the subheading "How do I run a Macro in Microsoft Excel". It works quite well.
This will only work if you run it on a Windows system with Excel installed
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $filename = 'book1.xls';
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')|| Win32::OLE->new('Excel.Application', 'Quit'); # use the Excel application if it's open, otherwise open new
my $Book = $Excel->Workbooks->Open( $filename ); # open the file
$Excel->Run("macro_name");
$Book->Save; #optional - save any changes made by the macro
$Book->Close;
perlmonks.org content © perlmonks.org and Lhamo_rin, marto, murugu, terce
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03