how to close powerpoint

22 次查看(过去 30 天)
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

采纳的回答

Jack
Jack 2023-3-30
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 个评论
Ihaveaquest
Ihaveaquest 2023-3-30
this works great thank you - one thing i noticed it kills all open powerpoint files - how may i pinpoint to a specific powerpoint

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Report Generator 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by