2
votes

I have a macro written in powerpoint and i need to call it from my perl script, it is possible to call a macro from Excel using $Excel->Run("MYMACRONAMEHERE"); but using "Run" with powerpoint is giving the below error:

OLE exception from "Microsoft PowerPoint 2010": Application.Run : Invalid request. Sub or function not defined. Win32::OLE(0.1709) error 0x80048240 in METHOD/PROPERTYGET "Run"

below is the perl i am usign to call the macro from powerpoint:

my $filename = "<path>";
my $PptApp  = Win32::OLE->GetActiveObject('PowerPoint.Application')|| Win32::OLE->new('PowerPoint.Application', 'Quit'); 
$PptApp->{Visible} = 1;
my $Presentation = $PptApp->Presentations->Open({FileName=>"$filename",ReadOnly=>0});
$PptApp->Run("macro_name");
2
Your code is correct. Are you sure you have macro with given name defined?gangabass

2 Answers

1
votes

You're using the power point Application object to run an Excel macro. That's not going to work. You'll need to get an instance of Excel and use its Application object to run the Excel macro. Alternatively, you could copy the VBA code into a PowerPoint module.

0
votes

The macro must be defined and, I'm pretty sure, must be declared as Public.

And, from MSDN (http://msdn.microsoft.com/en-us/library/office/ff744221(v=office.15).aspx):

The name of the procedure to be run. The string can contain the following: a loaded presentation or add-in file name followed by an exclamation point (!), a valid module name followed by a period (.), and the procedure name. For example, the following is a valid MacroName value: "MyPres.ppt!Module1.Test."


However, if the procedure is declared Public and is part of a loaded add-in, you should only need to supply the procedure name.