Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Macro in Powerpoint from MATLAB

Subject: Macro in Powerpoint from MATLAB

From: Lottar Munoz

Date: 28 Jan, 2009 17:31:02

Message: 1 of 11

Hi guys!!

I've been fighting against Matlab almost the whole day and now i've to say i'm a little tired and almost defeated by it...so i need ur help!!!

i wrote a simple program to open a ppt presentation from matlab via actxserver. This is ok, but then i want to run a macro saved in the presentation and i've no fucking idea how to do it!!! i tried the same with a excel file and it works but i cannot understand why not with powerpoint!! above i include the code...can u help me??

g = actxserver('PowerPoint.Application');
g.Visible = 1;
Presentations = g.Presentations;
Presentation = invoke(Presentations,'Open','C:\...\Presentation.ppt')
Application = Presentation.Application;
invoke(Application,'Run','unbold');

If u change it for Excel it works but with powerpoint it doesnt!! and of course the name of the macro is the correct one and it works since i tested in powerpoint. the path is also correct so the problem is in the last line. Matlab gives me that:

??? No method 'Run' with matching signature found for class
'Interface.Microsoft_PowerPoint_11.0_Object_Library._Application'.

It seems there is a problem with the function call. Here i include also the fuction Run:
Application.invoke
Run = Variant Run(handle, string, SafeArray(Variant))

but..what is each element of the command??

I really need help so everything is welcome!

cheers,

Lottar.

Subject: Macro in Powerpoint from MATLAB

From: Lottar Munoz

Date: 29 Jan, 2009 23:58:01

Message: 2 of 11

Come on please!!

really anybody doesnt know anything about it?? i really need ur help!!! it's hard to say it but i'm almost desperated after spending too many hours with this f****** program!

please!!!!

Subject: Macro in Powerpoint from MATLAB

From: Walter Roberson

Date: 30 Jan, 2009 05:14:32

Message: 3 of 11

Lottar Munoz wrote:

> really anybody doesnt know anything about it?? i really need ur help!!!

Sorry, I've never used Matlab on Windows, I don't know much at all about ActiveX,
I don't know much at all about powerpoint (I didn't even know it -had- macros).
Oh yes, and I'm off sick today.

> it's hard to say it but i'm almost desperated after spending too many hours with
> this f****** program!

If you need the answer urgently, open a support call or hire a consultant.
This is the "All Volunteer, All of The Time" newsgroup, and that means
we answer when we feel like it, if we know at all.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Macro in Powerpoint from MATLAB

From: Yair Altman

Date: 15 Feb, 2009 07:48:04

Message: 4 of 11

"Lottar Munoz" <munoz@vki.ac.be>...
> invoke(Application,'Run','unbold');
> If u change it for Excel it works but with powerpoint it doesnt!! and of course the name of the macro is the correct one and it works since i tested in powerpoint. the path is also correct so the problem is in the last line. Matlab gives me that:
>
> ??? No method 'Run' with matching signature found for class
> 'Interface.Microsoft_PowerPoint_11.0_Object_Library._Application'.
>
> It seems there is a problem with the function call. Here i include also the fuction Run:
> Application.invoke
> Run = Variant Run(handle, string, SafeArray(Variant))

change to: invoke(Application,'Run','unbold',[]);

and next time be more polite - you'll find that it may attract less antagonism from the people from whom you asking for free help.

Yair altman
http://ymasoftware.com

Subject: Macro in Powerpoint from MATLAB

From: Amit Batifkoff

Date: 14 Dec, 2009 08:53:05

Message: 5 of 11

Hello Yair,
Thank you for answering this question. I have a follow up on it.
I want to add an hyperlink (e.g. 'c:\amit\flower.tif') to an image I add to a powerpoint.

pic1 = invoke(new_slide.Shapes,'Paste');

How can I do it?

Best Regards,
Amit.


"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <gn8hbk$bu0$1@fred.mathworks.com>...
> "Lottar Munoz" <munoz@vki.ac.be>...
> > invoke(Application,'Run','unbold');
> > If u change it for Excel it works but with powerpoint it doesnt!! and of course the name of the macro is the correct one and it works since i tested in powerpoint. the path is also correct so the problem is in the last line. Matlab gives me that:
> >
> > ??? No method 'Run' with matching signature found for class
> > 'Interface.Microsoft_PowerPoint_11.0_Object_Library._Application'.
> >
> > It seems there is a problem with the function call. Here i include also the fuction Run:
> > Application.invoke
> > Run = Variant Run(handle, string, SafeArray(Variant))
>
> change to: invoke(Application,'Run','unbold',[]);
>
> and next time be more polite - you'll find that it may attract less antagonism from the people from whom you asking for free help.
>
> Yair altman
> http://ymasoftware.com

Subject: Macro in Powerpoint from MATLAB

From: Yair Altman

Date: 14 Dec, 2009 10:03:02

Message: 6 of 11

"Amit Batifkoff" <amitbat@hotmail.com> wrote in message <hg4udh$ln5$1@fred.mathworks.com>...
> Hello Yair,
> Thank you for answering this question. I have a follow up on it.
> I want to add an hyperlink (e.g. 'c:\amit\flower.tif') to an image I add to a powerpoint.
>
> pic1 = invoke(new_slide.Shapes,'Paste');
>
> How can I do it?
>
> Best Regards,
> Amit.

This is the way to solve this and every other similar problem with VBA-to-Matlab code:
1. Start recording a new macro
2. Do your requested operations (example: add the hyperlink)
3. Stop the macro recording
4. Edit the macro VB code (Tools/Macro menu)
5. Convert the VB code into Matlab code as shown above and elsewhere

Yair altman
http://ymasoftware.com

Subject: Macro in Powerpoint from MATLAB

From: minipan

Date: 15 Dec, 2009 08:00:25

Message: 7 of 11

On Dec 14, 12:03 pm, "Yair Altman" <altmany...@gmailDEL.comDEL> wrote:
> "Amit Batifkoff" <amit...@hotmail.com> wrote in message <hg4udh$ln...@fred.mathworks.com>...
> > Hello Yair,
> > Thank you for answering this question. I have a follow up on it.
> > I want to add an hyperlink (e.g. 'c:\amit\flower.tif') to an image I add to a powerpoint.
>
> > pic1 = invoke(new_slide.Shapes,'Paste');
>
> > How can I do it?
>
> > Best Regards,
> > Amit.
>
> This is the way to solve this and every other similar problem with VBA-to-Matlab code:
> 1. Start recording a new macro
> 2. Do your requested operations (example: add the hyperlink)
> 3. Stop the macro recording
> 4. Edit the macro VB code (Tools/Macro menu)
> 5. Convert the VB code into Matlab code as shown above and elsewhere
>
> Yair altmanhttp://ymasoftware.com


Yair, Thank you for the quick replay.

In the ppt VB I get:
Sub test()
With ActiveWindow.Selection.ShapeRange.ActionSettings
(ppMouseClick).Hyperlink
        .Address = "c:\amit\flower.tif"
        .SubAddress = ""
        .ScreenTip = ""
        .TextToDisplay = ""
    End With
End Sub

Could you assist me with matlabizing that.

Thanks again,
Amit.

Subject: Macro in Powerpoint from MATLAB

From: Yair Altman

Date: 15 Dec, 2009 10:43:03

Message: 8 of 11

minipan <batikoff@gmail.com> wrote in message <d811d2d0-128a-4b44-8129-a8ba2c96a0a3@y32g2000prd.googlegroups.com>...
> On Dec 14, 12:03?pm, "Yair Altman" <altmany...@gmailDEL.comDEL> wrote:
> > "Amit Batifkoff" <amit...@hotmail.com> wrote in message <hg4udh$ln...@fred.mathworks.com>...
> > > Hello Yair,
> > > Thank you for answering this question. I have a follow up on it.
> > > I want to add an hyperlink (e.g. 'c:\amit\flower.tif') to an image I add to a powerpoint.
> >
> > > pic1 = invoke(new_slide.Shapes,'Paste');
> >
> > > How can I do it?
> >
> > > Best Regards,
> > > Amit.
> >
> > This is the way to solve this and every other similar problem with VBA-to-Matlab code:
> > 1. Start recording a new macro
> > 2. Do your requested operations (example: add the hyperlink)
> > 3. Stop the macro recording
> > 4. Edit the macro VB code (Tools/Macro menu)
> > 5. Convert the VB code into Matlab code as shown above and elsewhere
> >
> > Yair altmanhttp://ymasoftware.com
>
>
> Yair, Thank you for the quick replay.
>
> In the ppt VB I get:
> Sub test()
> With ActiveWindow.Selection.ShapeRange.ActionSettings
> (ppMouseClick).Hyperlink
> .Address = "c:\amit\flower.tif"
> .SubAddress = ""
> .ScreenTip = ""
> .TextToDisplay = ""
> End With
> End Sub
>
> Could you assist me with matlabizing that.
>
> Thanks again,
> Amit.

it would be something like this (pseudo-code - you will need to play with it):

app = actxserver('PowerPoint.Application');
shape = app.ActiveWindow.Selection.ShapeRange;
shape.ActionSettings(ppMouseClick).Hyperlink.Address='c:\amit\flower.tif';

(Get the numeric value of ppMouseClick=1 from Google)

Yair Altman
http;//UndocumentedMatlab.com

Subject: Macro in Powerpoint from MATLAB

From: Amit Batifkoff

Date: 15 Dec, 2009 18:19:04

Message: 9 of 11

Hi Yair,

The best I could get, by digging in the methods is:

ppt = actxserver('PowerPoint.Application');
op = invoke(ppt.Presentations,'Add');
new_slide = invoke(op.Slides,'Add',slide_count,11);

K>> get(new_slide.Hyperlinks)
          Count: 2
    Application: [1x1 Interface.Microsoft_PowerPoint_11.0_Object_Library._Application]
         Parent: [1x1 Interface.Microsoft_PowerPoint_11.0_Object_Library._Slide]

Where the count is changing when I (manually) add or remove a hyperlink from an object in the power point, but I can't find a property called address, nor can I find the link I've manually entered.

Again, thank you for the help so far, and any farther help is much appreciated.

Best Regards,
Amit.


"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hg7p7n$ceq$1@fred.mathworks.com>...
> minipan <batikoff@gmail.com> wrote in message <d811d2d0-128a-4b44-8129-a8ba2c96a0a3@y32g2000prd.googlegroups.com>...
> > On Dec 14, 12:03?pm, "Yair Altman" <altmany...@gmailDEL.comDEL> wrote:
> > > "Amit Batifkoff" <amit...@hotmail.com> wrote in message <hg4udh$ln...@fred.mathworks.com>...
> > > > Hello Yair,
> > > > Thank you for answering this question. I have a follow up on it.
> > > > I want to add an hyperlink (e.g. 'c:\amit\flower.tif') to an image I add to a powerpoint.
> > >
> > > > pic1 = invoke(new_slide.Shapes,'Paste');
> > >
> > > > How can I do it?
> > >
> > > > Best Regards,
> > > > Amit.
> > >
> > > This is the way to solve this and every other similar problem with VBA-to-Matlab code:
> > > 1. Start recording a new macro
> > > 2. Do your requested operations (example: add the hyperlink)
> > > 3. Stop the macro recording
> > > 4. Edit the macro VB code (Tools/Macro menu)
> > > 5. Convert the VB code into Matlab code as shown above and elsewhere
> > >
> > > Yair altmanhttp://ymasoftware.com
> >
> >
> > Yair, Thank you for the quick replay.
> >
> > In the ppt VB I get:
> > Sub test()
> > With ActiveWindow.Selection.ShapeRange.ActionSettings
> > (ppMouseClick).Hyperlink
> > .Address = "c:\amit\flower.tif"
> > .SubAddress = ""
> > .ScreenTip = ""
> > .TextToDisplay = ""
> > End With
> > End Sub
> >
> > Could you assist me with matlabizing that.
> >
> > Thanks again,
> > Amit.
>
> it would be something like this (pseudo-code - you will need to play with it):
>
> app = actxserver('PowerPoint.Application');
> shape = app.ActiveWindow.Selection.ShapeRange;
> shape.ActionSettings(ppMouseClick).Hyperlink.Address='c:\amit\flower.tif';
>
> (Get the numeric value of ppMouseClick=1 from Google)
>
> Yair Altman
> http;//UndocumentedMatlab.com

Subject: Macro in Powerpoint from MATLAB

From: Peter Lorin Rasmussen

Date: 18 Jul, 2011 06:02:07

Message: 10 of 11

"Lottar Munoz" <munoz@vki.ac.be> wrote in message <glq4om$27t$1@fred.mathworks.com>...
> Hi guys!!
>
> I've been fighting against Matlab almost the whole day and now i've to say i'm a little tired and almost defeated by it...so i need ur help!!!
>
> i wrote a simple program to open a ppt presentation from matlab via actxserver. This is ok, but then i want to run a macro saved in the presentation and i've no fucking idea how to do it!!! i tried the same with a excel file and it works but i cannot understand why not with powerpoint!! above i include the code...can u help me??
>
> g = actxserver('PowerPoint.Application');
> g.Visible = 1;
> Presentations = g.Presentations;
> Presentation = invoke(Presentations,'Open','C:\...\Presentation.ppt')
> Application = Presentation.Application;
> invoke(Application,'Run','unbold');
>
> If u change it for Excel it works but with powerpoint it doesnt!! and of course the name of the macro is the correct one and it works since i tested in powerpoint. the path is also correct so the problem is in the last line. Matlab gives me that:
>
> ??? No method 'Run' with matching signature found for class
> 'Interface.Microsoft_PowerPoint_11.0_Object_Library._Application'.
>
> It seems there is a problem with the function call. Here i include also the fuction Run:
> Application.invoke
> Run = Variant Run(handle, string, SafeArray(Variant))
>
> but..what is each element of the command??
>
> I really need help so everything is welcome!
>

I also had some troubles running PowerPoint VBA from Matlab. I think the problem is that you need to load the VB project into Matlab before you can run it.

None the less, this function works for me in Office 2002

function runPowerPointMacro(fileName,macroName,varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Run a powerpoint macro within a specified powerpoint
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % Initiate active X component
    powerPoint=actxserver('PowerPoint.Application');
    
    % Visible
    powerPoint.Visible=1;
    
    % Minimize powerpoint
    powerPoint.WindowState=2;
    
    % Load presentations object
    presentations=powerPoint.presentations;
    
    % Open file
    presentation=invoke(presentations,'open',fileName);
    
    % Load VBA project
    k=presentation.VBProject.Collection.get();
    
    % Run Macro
    k=invoke(presentation.application,'run',macroName,varargin{:});
    
    % Close all
    presentation.Save;
    presentation.Close;
    powerPoint.Quit;
    powerPoint.delete;


end

Hope it helps

/Peter

Subject: Macro in Powerpoint from MATLAB

From: Yair Altman

Date: 20 Jul, 2011 19:40:09

Message: 11 of 11

Reposted with some additional related details:

http://UndocumentedMatlab.com/blog/running-vb-code-in-matlab/

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us