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