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
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!