Editing PowerPoint While It is Open
14 views (last 30 days)
Hi. I'm trying to write code which will add or edit images in a powerpoint. The only problem I have now is that I can only edit it while the powerpoint window is closed. If it is open, the following error appears:
Error using mlreportgen.ppt.Presentation/find
Cannot open file. C:/Users/me/folder/my_powerpoint.pptx
Error in add_to_ppt (line 5)
Does anyone know a way of editing the powerpoint while it is open? Thanks in advance!
Here is the function I'm using:
slides = Presentation('C:\Users\me\folder\my_powerpoint.pptx','C:\Users\me\folder\my_powerpoint.pptx');
Guillaume on 6 Jul 2019
When a file is open in powerpoint, powerpoint locks it so no other program can edit it. This is why you get an error when trying to open the file.
Instead of using mlreport to edit the file, you could talk directly to powerpoint and send it instructions to modify the file. The downside of this is you can't use the report generator anymore, you'll have to do everything yourself. You would have to use actxGetRunningServer to find the open powerpoint instance and then use the powerpoint object model to do what you want. Not impossible but a lot of work if you're not familiar with it.
Frankly, the simplest thing to do is to ensure that you've closed the file before editing with matlab. This would also ensure that if there were some unsaved changed in the powerpoint file, they are actually saved before the edition with matlab.