how to close powerpoint

22 ビュー (過去 30 日間)
Ihaveaquest
Ihaveaquest 2023 年 3 月 29 日
コメント済み: Ihaveaquest 2023 年 3 月 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 Center および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by