Converting to Microsoft Office drawing object from script
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Use COM Objects in MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!