Run-time Error creating an app Excel Object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Im trying to create an Excel Object in .NET, many times I did in VB6
So here the code in a .NET window form

Private Sub btnExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExcel.Clic
Dim FileName As Strin
Dim appExcel As New Excel.Application(
Dim Hoja As Excel.Workshee
FileName = "anyfile.xls

Hoja = appExcel.Workbooks.Open(FileName) 'IN THIS LINE OCURRS THE ERROR

End Su

"Run-time exception thrown : System.Runtime.InteropServices.COMException - Old format or invalid type library.
 
Hi Vic

I am not sure if this will help but this is how i do it in C#. You should be able to omit the 'missing' values in VB.Which version of office are you using because if it is Office XP, you should install the Primary Interop Assemblies

string fileName = "C:\...."
string password =""; // Just leave this blank if you don't want to suply a passwor

object missing = System.Reflection.Missing.Value
Excel._Application excel = new Excel.ApplicationClass( )
excel.Visible = true

// Office version 200
// excel.Workbooks.Open(fileName, false, false, missing, password, missing, missing, missing, missing, missing, missing, missing, missing)

// Office version 10 (XP
excel.Workbooks.Open(fileName, false, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
 
Hi Vic,

If I try this I get a cast error which is caused by the fact that the 'Open'
method returns a 'Workbook' object and NOT a 'Worksheet' object. If I change
your Dim statement to...

Dim Hoja As Excel.Workbook

....then everything works fine. BTW, I'm not sure if automation objects are
different for older versions of Excel but I am running with Excel 2003.

Gary

Vic said:
Im trying to create an Excel Object in .NET, many times I did in VB6
So here the code in a .NET window form :

Private Sub btnExcel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExcel.Click
Dim FileName As String
Dim appExcel As New Excel.Application()
Dim Hoja As Excel.Worksheet
FileName = "anyfile.xls"

Hoja = appExcel.Workbooks.Open(FileName) 'IN THIS LINE OCURRS THE ERROR.

End Sub

"Run-time exception thrown : System.Runtime.InteropServices.COMException -
Old format or invalid type library."
 
Back
Top