diff --git a/Public/ConvertTo-ExcelXlsx.ps1 b/Public/ConvertTo-ExcelXlsx.ps1 index 578445e0..aedb1b15 100644 --- a/Public/ConvertTo-ExcelXlsx.ps1 +++ b/Public/ConvertTo-ExcelXlsx.ps1 @@ -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 { + $workbook.SaveAs($xlsxPath, $xlFixedFormat) + } } finally { if ($null -ne $Excel.ActiveWorkbook) {