use try-finally

This commit is contained in:
Edward Miller
2024-05-17 23:24:11 -05:00
parent 57bb049111
commit 722516de7c

View File

@@ -45,11 +45,15 @@ function ConvertTo-ExcelXlsx {
throw "Could not create Excel.Application ComObject. Please verify that Excel is installed." throw "Could not create Excel.Application ComObject. Please verify that Excel is installed."
} }
$Excel.Visible = $false try {
$null = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true) $Excel.Visible = $false
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat) $null = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
$Excel.ActiveWorkbook.Close() $Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
$Excel.Quit() }
finally {
$Excel.ActiveWorkbook.Close()
$Excel.Quit()
}
} }
} }