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

Excel automation

Status
Not open for further replies.

jonnyknowsbest

Technical User
Feb 3, 2004
163
GB
I have two very separate, very private subroutines. They both employ the following code:

Dim xlApp As New myExcel.Application
Dim xlBook As New myExcel.Workbook
Dim xlSheet As New myExcel.Worksheet

xlBook = xlApp.Workbooks.Add
xlSheet = xlBook.Worksheets.Add

One subroutine works fine, the other one fails on the "xlBook = xlApp.Workbooks.Add" line, with the following error:

Additional information: COM object with CLSID {00020819-0000-0000-C000-000000000046} is either not valid or not registered.

Please help me, this is doing my head in!!!
 
I don't normally do it that way; I use early binding instead of late binding. (in other words, using a reference instead of CreateObject, which is what I think you are doing) That way, the code would simply be:

Code:
Dim XL as New Excel.Application
XL=New Excel.Application

'Open XL
XL.Visible=True 'Change to false for an invisible app
XL.Workbooks.Add

I've never had a Com exception using this method.

I hope this helps.





Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top