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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem MS Excel, can't use ordinary code

Status
Not open for further replies.

Lyubomyr

Programmer
Jul 23, 2005
21
UA
I'm writing
Code:
        Dim xlApp As Excel.Application
        Dim xlWb As Excel.Workbook
        Dim xlSh As Excel.Worksheet

        xlApp = CreateObject("Excel.Application")
        xlWb = xlApp.Workbooks.Add()
        xlSh = xlWb.Item(1)
        xlSh.Name = "My Sheet"

        xlWb.SaveAs("d:\reports\report1.xls")
        xlApp.Quit()

The problem is in the line:

xlWb = xlApp.Workbooks.Add()

it terminates the execution and shows me an exception:

Old format or invalid type library

I take reference Microsoft Excel Librery 11.0 Object Library
(Ver 1.5)
from
C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE

Any ideas?
 
This is what I use in .Net:

Public Sub AddWorkbook(Optional ByVal Template As Object = Nothing)
If Template = Nothing Then
XLApp.Workbooks.Add()
Else
XLApp.Workbooks.Add(Template)
End If

End Sub

I hope this helps.



Ron Repp
 
In my case i thing the problem in the refernce I connect.

I tried your code RonRepp but it doesn't solve the problem

Actually I'm doing almost the same that you suggest(I also tried your code) but i still have the same:

"Old format or invalid type library" exception at runtime

Something other advices about? references i connect?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top