procedure TForm1.OpenAnExistingPowerPointFileAndSaveAs(Sender: TObject);
var
PowerPointFileName, PowerPointFileNameNew: String;
PowerPointApplication, PowerPointPresentation: Variant;
begin
//be sure ComObj and Variants units are included in the "uses" clause
PowerPointFileName := 'C:\PhysiologyWeb\delphi_code_examples\powerpoint_file.pptx'; //replace file name with the name of your file
PowerPointFileNameNew := 'C:\PhysiologyWeb\delphi_code_examples\powerpoint_file_new.pptx'; //replace file name with the name of your file
PowerPointApplication := Null;
PowerPointPresentation := Null;
try
//create PowerPoint OLE
PowerPointApplication := CreateOleObject('PowerPoint.Application');
except
PowerPointApplication := Null;
//add error/exception handling code as desired
end;
If VarIsNull(PowerPointApplication) = False then
begin
try
PowerPointApplication.Visible := True; //set to False if you do not want to see the activity in the background
PowerPointApplication.DisplayAlerts := False; //ensures message dialogs do not interrupt the flow of your automation process. May be helpful to set to True during testing and debugging.
//Open PowerPoint Presentation
try
PowerPointPresentation := PowerPointApplication.Presentations.Open(PowerPointFileName);
//reference
//https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentations.open
except
PowerPointPresentation := Null;
//add error/exception handling code as desired
end;
If VarIsNull(PowerPointPresentation) = False then
begin
PowerPointApplication.ActivePresentation.SaveAs(PowerPointFileNameNew);
//reference
//https://docs.microsoft.com/en-us/office/vba/api/powerpoint.application.activepresentation
end;
finally
PowerPointApplication.ActivePresentation.Close;
PowerPointApplication.DisplayAlerts := True;
PowerPointApplication.Quit;
PowerPointPresentation := Unassigned;
PowerPointApplication := Unassigned;
end;
end;
end;
Posted: Saturday, December 5, 2020
Last updated: Tuesday, March 18, 2025