diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 71ef43e..10c1360 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -473,6 +473,10 @@ function Convert-Files { $xlsxPath = Join-Path $env:TEMP $xlsxFileName $downloadPath = Join-Path $env:TEMP $originalFileName + # Convert the paths to proper Windows paths + $xlsxPath = [System.IO.Path]::GetFullPath($xlsxPath) + $downloadPath = [System.IO.Path]::GetFullPath($downloadPath) + try { # Open Excel $excel = New-Object -ComObject Excel.Application @@ -482,12 +486,14 @@ function Convert-Files { try { $workbook = $excel.Workbooks.Open($downloadPath) - # Save as XLSX - use the full path with quotes + # Save as XLSX using the full path $workbook.SaveAs([string]$xlsxPath, 51) # 51 = xlOpenXMLWorkbook (*.xlsx) - $workbook.Close($false) + $workbook.Close($true) # True to save changes + + Start-Sleep -Seconds 1 # Give Excel time to finish saving # Verify the file was created - if (-not (Test-Path $xlsxPath)) { + if (-not (Test-Path -LiteralPath $xlsxPath)) { throw "Excel SaveAs succeeded but file not found at: $xlsxPath" } }