Skip to content

Commit

Permalink
use try-finally
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmiller-mesirow committed May 18, 2024
1 parent 57bb049 commit 722516d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Public/ConvertTo-ExcelXlsx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ function ConvertTo-ExcelXlsx {
throw "Could not create Excel.Application ComObject. Please verify that Excel is installed."
}

$Excel.Visible = $false
$null = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
$Excel.ActiveWorkbook.Close()
$Excel.Quit()
try {
$Excel.Visible = $false
$null = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
}
finally {
$Excel.ActiveWorkbook.Close()
$Excel.Quit()
}
}
}

0 comments on commit 722516d

Please sign in to comment.