how to close powerpoint
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ihaveaquest
am 29 Mär. 2023
Kommentiert: Ihaveaquest
am 30 Mär. 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
0 Kommentare
Akzeptierte Antwort
Jack
am 30 Mär. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Report Generator finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!