Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using excel in .NET problems

Status
Not open for further replies.

stx

Programmer
Sep 24, 2002
62
BE
Hi

This is my code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet

' Start Excel and get Application object.
oXL = CreateObject("Excel.Application")
oXL.Visible = True

' Get a new workbook.
oWB = oXL.Workbooks.Add
oSheet = oWB.ActiveSheet

' Add table headers going cell by cell.
oSheet.Cells(1, 1).Value = "First Name"
oSheet.Cells(1, 2).Value = "Last Name"
oSheet.Cells(1, 3).Value = "Full Name"
oSheet.Cells(1, 4).Value = "Salary"

' Format A1:D1 as bold, vertical alignment = center.
With oSheet.Range("A1", "D1")
.Font.Bold = True
.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
End With
End Sub


I got this code from the microsoft website:

I'm running visual studio.NET 2003 on a windows xp pro system with office xp pro on it.
I added the necessary references to my project.
(com reference to excel 10.0 library)

The following error is what i get:
Old format or invalid type library.


I already re-installed my office xp but that resolved nothing.

I'm getting very desperate.

Anyone any thoughts.
Any help is welcome.
Thnx.
 
There's also an Office library that's separate from the Excel 10 library; I don't know if that would make a difference or not...
 
Thnx for the reply benlinkknilneb

No, adding the office library doesn't change a thing.

At the followong line of code i still get the same error:
oWB = oXL.Workbooks.Add


Any thoughts?
please!

thnx

 
I'm not sure why it doesn't work, but the syntax you're using is the old method for opening an excel document. I was under the impression that it would still work. Here's the way I've done it:

Dim xlapp As New Excel.Application()
Dim xlbook As Excel.Workbook
xlbook = xlapp.Workbooks.Open(PathToExcelFile)

Of course, that opens an existing doc for editing... but I was thinking more about the declarations. Try changing your declarations to the above rather than using the CreateObject() function.
 
benlinkknilneb

i used your 3 lines of code and i got the same error message as before on the last line !

Error:
Old format or invalid type library.

Any thoughts

thnx for replying
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top