Clear Filters
Clear Filters

Converting to Microsoft Office drawing object from script

4 views (last 30 days)
I have code that prints a figure onto the clipboard in emf, then pastes it into a PowerPoint slide.
Now if I go to PowerPoint and ungroup the figure, I get a warning that it needs to be converted to Microsoft Office drawing object, I say Yes and then I can ungroup and edit the figure in PowerPoint.
I'm trying to implement this last step in my script and I'm running into a funny problem. After I paste the figure into the slide I get the handle of a ShapeRange object, let's call it h_ppt. Then I can try to call h_ppt.Ungroup.
Here's the thing:
  • If I run the script it fails, giving a generic Interface.../Ungroup error.
  • If I go to my PowerPoint presentation, go back to matlab and run h_ppt.Ungroup, it works!
  • I tried using ppApplication.Activate to open the PowerPoint window before it runs ungroup, but it doesn't work.
I am using Matlab 2015b and Microsoft Office Professional 2010.
Here's the code:
function fig2ppt( h_mat )
%FIG2PPT Copy figure with handle h_mat and paste in currently open PowerPoint
%presentation. It will add a new slide at the end before pasting.
pp = actxserver('PowerPoint.Application');
pres = pp.Presentation.Item(1);
sl = pres.Slides.AddSlide(pres.Slides.Count+1,pres.SlideMaster.CustomLayouts.Item(7));
print(h_mat,'-clipboard','-dmeta')
h_ppt = sl.Shapes.PasteSpecial();
h_ppt.Align('msoAlignMiddles','msoTrue');
h_ppt.Align('msoAlignCenters','msoTrue');
sl.Select;
h_ppt.Ungroup;
delete(pp)
end

Accepted Answer

SuperNano
SuperNano on 28 Jul 2016
I found a workaround in case anyone's interested... For some reason Ungroup only fails when the image is pasted into a newly created slide, but works fine if the image is pasted onto an existing slide. So the solution is to paste it into the last existing slide, ungroup it, create the new slide, cut the ungrouped ShapeRange and paste into the new slide... Here's the code:
function fig2ppt( h_mat )
%FIG2PPT Copy figure in h_mat and paste in currently open PowerPoint
%presentation. It will add a new slide at the end before pasting.
pp = actxserver('PowerPoint.Application');
pres = pp.Presentation.Item(1);
pres.Slides.AddSlide(pres.Slides.Count+1,pres.SlideMaster.CustomLayouts.Item(7));
print(h_mat,'-clipboard','-dmeta')
h_ppt = pres.Slides.Item(pres.Slides.Count-1).Shapes.Paste;
h_ppt.Align('msoAlignMiddles','msoTrue');
h_ppt.Align('msoAlignCenters','msoTrue');
h_ppt = h_ppt.Ungroup;
h_ppt.Cut;
pres.Slides.Item(pres.Slides.Count).Shapes.Paste;
delete(pp)
end

More Answers (0)

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!