diff --git a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb index dc3bc12..09b97cd 100644 --- a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb +++ b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb @@ -1046,9 +1046,16 @@ Namespace ExcelOps ''' Public Overrides Sub RemoveVbaProject() - If Me.Workbook.VbaProject IsNot Nothing Then - Me.Workbook.VbaProject.Remove() - End If + Try + If Me.Workbook.VbaProject IsNot Nothing Then + 'known to fail with files saved by newer MS Excel versions + 'failure is not critical since next Me.Workbook.RemoveVBAProject() also does some cleanups to delete VBA from file + '=> so we just ignore these errors here + Me.Workbook.VbaProject.Remove() + End If + Catch ex As NullReferenceException + Catch ex As System.IO.EndOfStreamException + End Try Me.Workbook.RemoveVBAProject() End Sub diff --git a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb index d0291c1..235f6fb 100644 --- a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb +++ b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb @@ -1046,9 +1046,16 @@ Namespace ExcelOps ''' Public Overrides Sub RemoveVbaProject() - If Me.Workbook.VbaProject IsNot Nothing Then - Me.Workbook.VbaProject.Remove() - End If + Try + If Me.Workbook.VbaProject IsNot Nothing Then + 'known to fail with files saved by newer MS Excel versions + 'failure is not critical since next Me.Workbook.RemoveVBAProject() also does some cleanups to delete VBA from file + '=> so we just ignore these errors here + Me.Workbook.VbaProject.Remove() + End If + Catch ex As NullReferenceException + Catch ex As System.IO.EndOfStreamException + End Try Me.Workbook.RemoveVBAProject() End Sub