Problem opening Excel spreadsheeet

B

BGCSOCAL

I'm running VS 2005, Office 2003 tools and Office 2003 on Vista.
I'm having a problem opening an Excel 2003 spreadsheet using the following
code:
'try to open the spreadsheet
Try
oXL = CreateObject("Excel.Application")
oXL.Visible = True
oWB = oXL.Workbooks.Open("c:\Trash\GL Events (3004 items).XLS")
indExcel = True
Catch myException As Exception
'If cannot connect to spreadsheet, then show error
MsgBox("Access to Spreadsheet failed.", MsgBoxStyle.Exclamation,
myException.Message)
indExcel = False
GoTo Close
End Try

Excel starts and the spreadshet loads and then I get an error: Unable to
cast COM object of type Microsoft.Office.Interop.Excel.Workbookclass.

I haven't touched any programming for the last 3 years so I am deficient.
If some one can help me, I would appreciate it.

I was thinking that the fact that Office 2007 had previously been installed
on this PC might be the problem. From my research I can see that the two
together is a no no and that Office 2007 un-install may not be cleaning up
after itself enough. could this be the problem?
 
B

BGCSOCAL

The change turned out to be that I had defined oWB as Excel.Workbooks instead
of Excel.Workbook. Once I made that change all was good.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top