Skip to content

Commit

Permalink
Prevent error: "Unable to get the SaveAs property of the Workbook class"
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmiller-mesirow committed May 21, 2024
1 parent fa907da commit 265bee2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Public/ConvertTo-ExcelXlsx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ function ConvertTo-ExcelXlsx {

try {
$Excel.Visible = $false
$null = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
$workbook = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
if ($null -eq $workbook) {
Write-Host "Failed to open workbook"
} else {
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
}
}
finally {
if ($null -ne $Excel.ActiveWorkbook) {
Expand Down

0 comments on commit 265bee2

Please sign in to comment.