How Can I Access Individual Powerpoint Shapes from a collection; actxserver COM objects

36 views (last 30 days)
Hello All,
First time question asker!
I am trying to access multiple shapes (Title and Subtitle) one at a time in order to edit them in a PowerPoint presentation through the actxserver. However the collection of shapes does not seem to let me access the individual shapes - I have tried using indexing to access a specific shape but get the obvious index error below:
Index exceeds matrix dimensions.
I have read that accessing collections in MATLAB is a known issue, however I did not manage to find any solution - I am assuming it will involve the get command but I'm afraid I just haven't cracked it yet.
My code is as such:
%%Start an ActiveX session with PowerPoint:
ppt = actxserver('PowerPoint.Application');
ppt.Visible = 1;
pres = ppt.Presentations.Add;
% Apply Template
invoke(pres,'ApplyTemplate', template);
% Title Slide
title_slide = invoke(pres.Slides,'Add',1,1);
% This section works but only gives me access to the main title
title_shapes = get(title_slide.Shapes);
title = get(title_shapes.Title);
set(title.TextFrame.TextRange,'Text',main);
% When I try with the following line the error above is generated.
title_shape = get(title_slide.Shapes(1));
The rest of the code is not written (this is WIP) and the function is finished with the usual
% Quit PowerPoint
invoke(ppt,'Quit');
% End process
delete(ppt);
clear ppt pres;
The first slide invoked is a 'title' slide (containing title & subtitle). The template is simply a file with our company logo and not important. I am using MATLAB 2014a, and PowerPoint 2010.
If anyone can offer any advice/direction on how to access the shape it would be greatly appreciated!
Thanks, Andy

Accepted Answer

Andy L
Andy L on 21 Aug 2014
Edited: Andy L on 21 Aug 2014
Solved it!
Individual Shapes from the Shapes collection are accessed as Items. For a collection of two shapes (title and subtitle) I used the following code.
title_slide = invoke( pres.Slides,'Add',1,1 ); % Add Title Slide
title = get( title_slide.Shapes.Item(1) ); % Get Handle to title shape
subtitle = get( title_slide.Shapes.Item(2) ); % Get Handle to subtitle shape
set(title.TextFrame.TextRange ,'Text','Title' ); % Set Title Text to 'Title'
set(subtitle.TextFrame.TextRange,'Text','Subtitle'); % Set Subtitle Text to 'Subitle'
  1 Comment
Ivan
Ivan on 11 Jan 2016
Edited: Ivan on 11 Jan 2016
Thanks! Same can be used by predefined slides:
h = actxserver('PowerPoint.Application');
Presentation = h.Presentation.Open('YourPresentation.pptx');
Slide1 = Presentation.Slides.Item(1);

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!