1

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

This issue occurs only in MS Office 365 Version. In Excel 2024 it is working as intended.

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.

https://learn.microsoft.com/en-us/answers/questions/5883264/unable-to-save-saveas-xls-and-xlt-files-using-micr?page=1&orderby=Helpful&comment=answer-12761256&translated=false#newest-answer-comment

Thanks,

Akbar Husain.

1
  • Apologies, I have no time to test around with this stuff, but try setting : xlApp.msoAutomationSecurityLow=1 after creating the Excel Instance. This setting usually is to affect macro running, but PERHAPS it might also allow the saveAs. Worth a shot. Commented May 19 at 10:54

1 Answer 1

3

In Office 365, there is a Trust-Center setting where you can define which file types you trust. I have noticed it only recently (as I had to open a very old Excel 4 Workbook), but I cannot tell when it was introduced or if the default settings changed recently.

You reach this settings via

  • File->Options
  • Trust Center -> Button Trust Center
  • File Block Settings

Excel Trust Center File Block Settings

xls-files can contain Macros (and you can't tell from outside if they have or not). Checking "Open" or "Save", Excel prevents that you can open resp. save those files, so in my case, it is allowed to open xls files.


Update Haven't had a close enough look to the linked MS side, sorry for that. So my answer is basically repeating that.

To narrow down the problem: Have your tried to do the same simply with VBA?

Sub testSaveAs()

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

    Dim Wb As Workbook
    Set Wb = Workbooks.Open(pstrSrcFileName)
    Wb.SaveAs pstrDestFileName, xlExcel8
    Wb.Close False

End Sub

If this doesn't work, problem is on Excel side. If it works but your VB.Net code not, it's somehow related to Office Automation.

Sign up to request clarification or add additional context in comments.

3 Comments

This is covered in the linked post on Microsoft Q&A...
Yes, It is already covered.
Yes, it is working in VBA Code, but not in VB.net with Interop. So it looks like the issue is with Interop not VBA or Excel.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.