Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

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 6

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 6

> 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 6

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 6

> 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 6

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 6

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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
powerpoint Calves 26 Jul, 2007 21:00:22
activex Calves 26 Jul, 2007 21:00:22
textbox color Calves 26 Jul, 2007 21:00:22
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics