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:
Matlab ActiveX command for PowerPoint Multiline Title

Subject: Matlab ActiveX command for PowerPoint Multiline Title

From: Calves Stovall

Date: 18 Jul, 2007 19:11:42

Message: 1 of 10

Does anyone know how to use activeX in Maltab so that you can write a multiline title text?

Here's an excerpt of the code I'm using.

   titletext=sprintf('LINE1\nline2');

   writepath=pwd;
   clearppt='MC_default.ppt'
   outfileppt='TitleTest.ppt'
    
   clearppt = [writepath '\' clearppt];
   outfileppt = [writepath '\' outfileppt];

   % Start an ActiveX session with PowerPoint:
   ppt = actxserver('PowerPoint.Application');
   ppt.Visible = 1; % Keep Application Visible
   ppt.WindowState = 2; % Minimize PowerPoint window to taskbar

       % Open existing presentation:
       op = invoke(ppt.Presentations,'Open',clearppt);
  
       % Get current number of slides:
       slide_count = get(op.Slides,'Count');
    
       % Add a new slide (with title object):
       slide_count = int32(double(slide_count)+1);
       new_slide = invoke(op.Slides,'Add',slide_count,11);
    
       % Insert text into the title object:
       new_slide.Shapes.Title.TextFrame.TextRange.Text=titletext;

   % Save file as new:
   invoke(op,'SaveAs',outfileppt,1);

   % Close the presentation window:
   invoke(op,'Close');
   % Quit PowerPoint
   invoke(ppt,'Quit');
   % Close PowerPoint and terminate ActiveX:
   delete(ppt);


Unfortunatley the resulting title is:
    LINE1 line2
instead of:
    LINE1
    line2

Any help would be greatly appreciated.

Calves

Subject: Matlab ActiveX command for PowerPoint Multiline Title

From: Yair Altman

Date: 19 Jul, 2007 05:51:24

Message: 2 of 10

> Does anyone know how to use activeX in Maltab so that
> you can write a multiline title text?
>
> Here's an excerpt of the code I'm using.
>
> titletext=sprintf('LINE1\nline2');


Microsoft Office uses char(13) to split multi-line strings. Matlab's sprintf() uses char(10) for '\n', which is the reason it didn't work for you. So, do this instead:

  titletext = ['LINE1' char(13) 'line2'];

You might wish to try out OfficeDoc (http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=15192) in order to read/write/format PowerPoint and other MS Office documents without the hassle of low-level programming.

Yair Altman
http://www.ymasoftware.com

Subject: Matlab ActiveX command for PowerPoint Multiline Title

From: Calves

Date: 25 Jul, 2007 23:32:18

Message: 3 of 10

Thanks, worked great.

Another question. Can you tell me how to reference an already exisiting powerpoint slide in activeX so that I can update the title?

Calves

Subject: Matlab ActiveX command for PowerPoint Multiline Title

From: Yair Altman

Date: 26 Jul, 2007 04:58:13

Message: 4 of 10

> Can you tell me how to reference an already exisiting powerpoint slide in activeX?


slide = invoke(op.Slides,'Item',slideNumber);
invoke(slide,'Select');

Yair Altman
http://www.ymasoftware.com

Subject: Matlab ActiveX command for PowerPoint Text Box Color

From: Calves

Date: 27 Jul, 2007 00:55:45

Message: 5 of 10

Thanks again.
I have another one for you or anybody else out there that might be able to answer. I can not get the correct font color for my text box in PowerPoint using ActiveX.

    text_box=invoke(new_slide.Shapes,'AddTextbox','msoTextOrientationHorizontal', 259.25, 20.75, 200, 20);
    text_box.TextFrame.TextRange.Text='Hello';
    text_box.TextFrame.TextRange.Font.Size=8;
    text_box.TextFrame.TextRange.ParagraphFormat.Alignment = 'ppAlignCenter';
    text_box.TextFrame.TextRange.Font.Bold = 'msoFalse';
    text_box.TextFrame.TextRange.Font.Color.RGB='255,255,0;

When I examine the color attributes in PowerPoint it says the text RGB color is 230,242,38.

I also tried...

text_box.TextFrame.TextRange.Font.Color.RGB='(255,255,0)';

and this gave me a text RGB color of 26,13,217.

Obviously I'm doing something wrong, but I don't know what.

Any help would be greatly appreciated.
Thanks,
Calves

Subject: Matlab ActiveX command for PowerPoint Text Box Color

From: Calves

Date: 27 Jul, 2007 15:01:44

Message: 6 of 10

The RGB character string was being converted to an integer. The integer was then being used as an index to all the RGB colors (256^3 or 0->16777215). Here's how I corrected my problem and was able to get the correct text color for my textbox in PowerPoint.

    text_box=invoke(new_slide.Shapes,'AddTextbox','msoTextOrientationHorizontal', 259.25, 20.75, 200, 20);
    text_box.TextFrame.TextRange.Text='Hello';
    text_box.TextFrame.TextRange.Font.Size=8;
    text_box.TextFrame.TextRange.ParagraphFormat.Alignment = 'ppAlignCenter';
    text_box.TextFrame.TextRange.Font.Bold = 'msoFalse';
    %Convert RGB colors to an RGB color index
        RGBcolor=[255,0,255]; RGBcolor=rem(RGBcolor,256);
        RGBindex=RGBcolor(1)+RGBcolor(2)*256+RGBcolor(3)*65536;
    text_box.TextFrame.TextRange.Font.Color.RGB=RGBindex;


I hope this helps someone else out there.
Calves

Subject: Matlab ActiveX command for PowerPoint Text Box Color

From: Hiep

Date: 13 Mar, 2010 10:19:08

Message: 7 of 10

Hi.

How can I set the background color of the whole presentation to certain solid color like RGB(200,100,100). This may help, I think:
ActivePresentation.SlideMaster.Background.Fill.PresetGradient _
    Style:=msoGradientHorizontal, Variant:=1, _
    PresetGradientType:=msoGradientLateSunset

Also, can you help me explain how to write VBA commands in Matlab.
For eg, the following code from Developer help:
With ActivePresentation.Slides(1)
    .FollowMasterBackground = False
    .Background.Fill.PresetGradient Style:=msoGradientHorizontal, _
        Variant:=1, PresetGradientType:=msoGradientLateSunset
End With

Given op = invoke(ppt.Presentations,'Open',filespec,[],[],0).
How can I write the corresponding commands for these VBA code in Matlab?
I have tried:
 
invoke(op.Slides,'FollowMasterBackground',0);
invoke(op.Slides.Background.Fill,'PresetGradient', 'msoGradientHorizontal',1,'msoGradientLateSunset');
but it is not working.
From my observation of others' codes, it seems that the command will have the form of
invoke(method prefix,'method name','method args') as in invoke(op.Slides,'FollowMasterBackground',0);
Is it correct?
Another question: when should we use set/get/invoke? I am a little confused on this.
Thank you in advance!

Subject: Matlab ActiveX command for PowerPoint Text Box Color

From: Hiep

Date: 13 Mar, 2010 10:22:06

Message: 8 of 10

Hi.

How can I set the background color of the whole presentation to certain solid color like RGB(200,100,100). This may help, I think:
ActivePresentation.SlideMaster.Background.Fill.PresetGradient _
    Style:=msoGradientHorizontal, Variant:=1, _
    PresetGradientType:=msoGradientLateSunset

Also, can you help me explain how to write VBA commands in Matlab.
For eg, the following code from Developer help:
With ActivePresentation.Slides(1)
    .FollowMasterBackground = False
    .Background.Fill.PresetGradient Style:=msoGradientHorizontal, _
        Variant:=1, PresetGradientType:=msoGradientLateSunset
End With

Given op = invoke(ppt.Presentations,'Open',filespec,[],[],0).
How can I write the corresponding commands for these VBA code in Matlab?
I have tried:
 
invoke(op.Slides,'FollowMasterBackground',0);
invoke(op.Slides.Background.Fill,'PresetGradient', 'msoGradientHorizontal',1,'msoGradientLateSunset');
but it is not working.
From my observation of others' codes, it seems that the command will have the form of
invoke(method prefix,'method name','method args') as in invoke(op.Slides,'FollowMasterBackground',0);
Is it correct?
Another question: when should we use set/get/invoke? I am a little confused on this.
Thank you in advance!

Subject: Matlab ActiveX command for PowerPoint 2007

From: William

Date: 22 Dec, 2010 00:25:05

Message: 9 of 10

"Calves" wrote in message <f7lole$dhk$1@fred.mathworks.com>...
> Does anyone know how to use activeX in Maltab so that you can write a multiline title text?
>
> Here's an excerpt of the code I'm using.
>
> titletext=sprintf('LINE1\nline2');
>
> writepath=pwd;
> clearppt='MC_default.ppt'
> outfileppt='TitleTest.ppt'
>
> clearppt = [writepath '\' clearppt];
> outfileppt = [writepath '\' outfileppt];
>
> % Start an ActiveX session with PowerPoint:
> ppt = actxserver('PowerPoint.Application');
> ppt.Visible = 1; % Keep Application Visible
> ppt.WindowState = 2; % Minimize PowerPoint window to taskbar
>
> % Open existing presentation:
> op = invoke(ppt.Presentations,'Open',clearppt);
>
> % Get current number of slides:
> slide_count = get(op.Slides,'Count');
>
> % Add a new slide (with title object):
> slide_count = int32(double(slide_count)+1);
> new_slide = invoke(op.Slides,'Add',slide_count,11);
>
> % Insert text into the title object:
> new_slide.Shapes.Title.TextFrame.TextRange.Text=titletext;
>
> % Save file as new:
> invoke(op,'SaveAs',outfileppt,1);
>
> % Close the presentation window:
> invoke(op,'Close');
> % Quit PowerPoint
> invoke(ppt,'Quit');
> % Close PowerPoint and terminate ActiveX:
> delete(ppt);
>
>
> Unfortunatley the resulting title is:
> LINE1 line2
> instead of:
> LINE1
> line2
>
> Any help would be greatly appreciated.
>
> Calves

This script worked well while I was using PPT 2003, (and Matlab 7.9.0) however after upgrading to PPT 2007 I get an error after op=..., see below. Are the commands different in PPT 2007?

>> op = invoke(ppt.Presentations,'Open',clearppt);
??? Invoke Error, Dispatch Exception:
Source: Microsoft Office PowerPoint 2007
Description: PowerPoint could not open the file.
Help File:
Help Context ID: 0

Subject: Matlab ActiveX command for PowerPoint Footer

From: William

Date: 22 Dec, 2010 02:52:04

Message: 10 of 10

"Calves" wrote in message <f7lole$dhk$1@fred.mathworks.com>...
> Does anyone know how to use activeX in Maltab so that you can write a multiline title text?
>
> Here's an excerpt of the code I'm using.
>
> titletext=sprintf('LINE1\nline2');
>
> writepath=pwd;
> clearppt='MC_default.ppt'
> outfileppt='TitleTest.ppt'
>
> clearppt = [writepath '\' clearppt];
> outfileppt = [writepath '\' outfileppt];
>
> % Start an ActiveX session with PowerPoint:
> ppt = actxserver('PowerPoint.Application');
> ppt.Visible = 1; % Keep Application Visible
> ppt.WindowState = 2; % Minimize PowerPoint window to taskbar
>
> % Open existing presentation:
> op = invoke(ppt.Presentations,'Open',clearppt);
>
> % Get current number of slides:
> slide_count = get(op.Slides,'Count');
>
> % Add a new slide (with title object):
> slide_count = int32(double(slide_count)+1);
> new_slide = invoke(op.Slides,'Add',slide_count,11);
>
> % Insert text into the title object:
> new_slide.Shapes.Title.TextFrame.TextRange.Text=titletext;
>
> % Save file as new:
> invoke(op,'SaveAs',outfileppt,1);
>
> % Close the presentation window:
> invoke(op,'Close');
> % Quit PowerPoint
> invoke(ppt,'Quit');
> % Close PowerPoint and terminate ActiveX:
> delete(ppt);
>
>
> Unfortunatley the resulting title is:
> LINE1 line2
> instead of:
> LINE1
> line2
>
> Any help would be greatly appreciated.
>
> Calves

Thanks to your clear example I see how to work with the "Title" in PPT. Is there a similar way I can work with the "Footer"?

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