From ffbe44da0a1d1ee4698ec607bd22ff2c2ceb400f Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Fri, 21 Feb 2025 11:30:09 -0800 Subject: [PATCH] fix: Add error handling for Excel SaveAs operation in Convert-Files function --- SharePointFunctions.ps1 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index fc17679..e8aaed1 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -482,9 +482,15 @@ function Convert-Files { $workbook = $excel.Workbooks.Open($downloadPath) Write-Host "Saving as XLSX: $xlsxPath" - # Save directly to the final path - $workbook.SaveAs([string]$xlsxPath, 51) # 51 = xlWorkbookDefault (xlsx format) - $workbook.Close($true) + try { + # Save directly to the final path + $workbook.SaveAs([string]$xlsxPath, 51) # 51 = xlWorkbookDefault (xlsx format) + $workbook.Close($true) + } + catch { + $script:txtStatus.Text += "Error during SaveAs: $($_.Exception.Message)`n" + throw "SaveAs failed: $($_.Exception.Message)" # Re-throw the exception to be caught by the outer catch + } Start-Sleep -Seconds 2 # Give Excel time to finish