Skip to main content
1 of 3

Unable to Save/SaveAs .xls and .xlt files using Microsoft.Office.Interop.Excel in VB.NET despite File Block Settings being unchecked in Trust Center

I have a Windows Forms application developed in VB.NET. I am trying to open an Excel file, manipulate it by adding new sheets and data, and then save the file using Microsoft.Office.Interop.Excel.

All Excel file extensions are working as expected except .xls and .xlt. For these two extensions, the application throws the following error:

Error: Exception from HRESULT: 0x800A03EC

The error occurs on the following line of code:

wb.SaveAs(pstrDestFileName, Excel.XlFileFormat.xlExcel8)

Code

VB.net

Sub Main()

    Dim xlApp As New Microsoft.Office.Interop.Excel.Application

    Dim wb As Microsoft.Office.Interop.Excel.Workbook

    Try

        xlApp = CreateObject("Excel.Application")

        xlApp.Interactive = False

        xlApp.DisplayAlerts = False

        xlApp.EnableEvents = False

        Dim pstrSrcFileName = "C:\Files\Book1.xls"

        Dim pstrDestFileName = "C:\Files\einfotree Copy of Book1.xls"

        wb = xlApp.Workbooks.Open(pstrSrcFileName, False, False, , "", "", , , , , , , False)

        wb.SaveAs(pstrDestFileName, Excel.XlFileFormat.xlExcel8)

        wb.Close(False)

        xlApp.Quit()

    Catch ex As Exception

       '

    End Try

End Sub

Note: Has there been any change in Microsoft Office versions or security settings that now restricts saving .xls or .xlt files using Interop?

Please go through the link and all the comments before replying, as this is the same issue I posted on Microsoft Q&A. Reviewing the complete discussion will help in understanding the exact issue and troubleshooting it in the right direction, which can help avoid multiple back-and-forth loops.

Thanks,

Akbar Husain.