Open Excel file .NET Framework 3.5

1

I wrote a VB .NET program that opens an Excel Workbook to put some values. Here is the code that open the file:

OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "Excel files (*.xls)|*.xls"
OpenFileDialog1.ShowDialog()
filePath = OpenFileDialog1.FileName
If System.IO.File.Exists(filePath) Then
  oExcel = CreateObject("Excel.Application")
  oExcel.Visible = True
  oBook = oExcel.Workbooks.Open(filePath)
End If

This worked well until I had to run it on an old computer wich didn't have .NET Framework 4.5 nor 4.0

I then change the Framework target to 3.5 and it gave me this error when running:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.VisualBasic.dll

Additional information: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))

I guess the way to open an Excel file is not the same for 3.5 or 4.5 so I don't know how I should do.

.net
vb.net
excel
asked on Stack Overflow Mar 26, 2014 by pocpoc47

1 Answer

1

Maybe you could find some earlier Interop Libs that used .Net 3.5 ?

When I was targeting Office 2010 and 2007, I found if I used the 2010 Interop DLLs I could use them to talk to 2007 and 2003 Office as well. I could not use any functionality that was only present in the later versions.

This was from different versions of .NET up to 3.5, I didn't try higher. Not sure if your using the same method as myself and I was using C#, but not sure that matters. If your using 32bit Office make sure you build x86 .net apps.

answered on Stack Overflow Mar 26, 2014 by AnthonyLambert • edited Mar 26, 2014 by AnthonyLambert

User contributions licensed under CC BY-SA 3.0