From fbbe981392517ed8b08e3fa58b5f004cdc163225 Mon Sep 17 00:00:00 2001 From: Domi Date: Mon, 29 Jan 2024 09:33:44 +0100 Subject: [PATCH] Corrected error skipping .ppt files --- OfficeConverter/MainWindow.xaml.cs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/OfficeConverter/MainWindow.xaml.cs b/OfficeConverter/MainWindow.xaml.cs index 63f0202..7604a94 100644 --- a/OfficeConverter/MainWindow.xaml.cs +++ b/OfficeConverter/MainWindow.xaml.cs @@ -348,13 +348,12 @@ namespace OfficeConverter private void ConvertPptToPptx(string pptFile, bool doSubfolders, bool doReplace) { PowerPoint.Application pptApp = new PowerPoint.Application(); - pptApp.DisplayAlerts = PowerPoint.PpAlertLevel.ppAlertsNone; - - // Set PowerPoint application visibility to false - pptApp.Visible = Microsoft.Office.Core.MsoTriState.msoFalse; try { + //pptApp = new PowerPoint.Application(); + pptApp.DisplayAlerts = PowerPoint.PpAlertLevel.ppAlertsNone; + PowerPoint.Presentation presentation = pptApp.Presentations.Open(pptFile); string targetFolderPath = ""; @@ -374,17 +373,29 @@ namespace OfficeConverter // Construct the new path for the .pptx file string newPptxPath = Path.Combine(targetFolderPath, Path.ChangeExtension(Path.GetFileName(pptFile), ".pptx")); presentation.SaveAs(newPptxPath, PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation); + + // Close the presentation without saving changes presentation.Close(); + + // Ensure PowerPoint is completely closed + Marshal.ReleaseComObject(presentation); + presentation = null; + } finally { - // Set PowerPoint application visibility back to true before quitting - pptApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; - // Quit PowerPoint - pptApp.Quit(); + if (pptApp != null) + { + pptApp.Quit(); + Marshal.ReleaseComObject(pptApp); + pptApp = null; + } } } + + + private void ConvertDocToDocx(string docFile, bool doSubfolders, bool doReplace) { Word.Application wordApp = new Word.Application();