how to close powerpoint

36 views (last 30 days)
Ihaveaquest
Ihaveaquest on 29 Mar 2023
Commented: Ihaveaquest on 30 Mar 2023
i am opening powerpoint and would like to check that pp is open and close it at the beginning of the script.
to avoid crashing later in the code when i open and write to powerpoint with same name.
Close(presentaion) does not work - somehow it doe snot have permission to do so
i tried delete
exit but nothing works
%Powerpoint function
import mlreportgen.ppt.*
taskToLookFor = 'Powerpnt.exe';
% Now make up the command line with the proper argument
% that will find only the process we are looking for.
commandLine = sprintf('tasklist /FI "IMAGENAME eq %s"', taskToLookFor)
% Now execute that command line and accept the result into "result".
[status result] = system(commandLine)
% Look for our program's name in the result variable.
itIsRunning = strfind(lower(result), lower(taskToLookFor))
if itIsRunning
if exist('Plotted Circulator', 'file')==0
system('taskkill /F /IM powerpoint.EXE');
end
else
end

Accepted Answer

Jack
Jack on 30 Mar 2023
If you want to close a PowerPoint presentation that you opened earlier in your script, you can use the Close method of the Presentation object. Here is an example:
import mlreportgen.ppt.*
% Open the PowerPoint presentation
presentation = Presentation('my_presentation.pptx');
open(presentation);
% ... some code that modifies the presentation ...
% Close the presentation
close(presentation);
If you want to check if PowerPoint is running before opening or closing a presentation, you can use the system function to execute a command line that lists all running processes, and then check if "Powerpnt.exe" is in the list. Here is an example:
% Check if PowerPoint is running
[status, result] = system('tasklist /FI "IMAGENAME eq Powerpnt.exe"');
is_running = contains(result, 'Powerpnt.exe');
% If PowerPoint is running, close the presentation
if is_running
try
% Open the presentation
presentation = Presentation('my_presentation.pptx');
open(presentation);
% ... some code that modifies the presentation ...
% Close the presentation
close(presentation);
% Close PowerPoint
system('taskkill /F /IM Powerpnt.exe');
catch ME
% Handle any errors
warning('Failed to close the PowerPoint presentation: %s', ME.message);
end
end
This code tries to open and close the presentation, and then close PowerPoint using the taskkill command. If any errors occur, a warning message is displayed.
  1 Comment
Ihaveaquest
Ihaveaquest on 30 Mar 2023
this works great thank you - one thing i noticed it kills all open powerpoint files - how may i pinpoint to a specific powerpoint

Sign in to comment.

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!