Excel 2003 - problem using from .Net

P

Peter A

Visual Studio 2005. The following code was working OK with Excel 2007:

Dim xlApp As New Excel.Application
Dim wb As Excel.Workbook
If Not File.Exists(AnionSpreadsheetName) Then
MsgBox("File not found: " & AnionSpreadsheetName)
Exit Sub
End If
wb = xlApp.Workbooks.Open(AnionSpreadsheetName)

Then, because my client uses Excel 2003 I uninstalled Office 2007 and
re-installed Office 2003. Now, on the last line (the call to Open) I get
this error:

Unable to cast COM object of type
'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type
'Microsoft.Office.Interop.Excel._Application'. This operation failed
because the QueryInterface call on the COM component for the interface
with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the
following error: could not be found. (Exception from HRESULT:
0x80030002 (STG_E_FILENOTFOUND)).

The file does exist and can be opened manually in Excel 2003, so I am at
a loss.

Thanks in advance,
 
P

Paul Clement

¤ Visual Studio 2005. The following code was working OK with Excel 2007:
¤
¤ Dim xlApp As New Excel.Application
¤ Dim wb As Excel.Workbook
¤ If Not File.Exists(AnionSpreadsheetName) Then
¤ MsgBox("File not found: " & AnionSpreadsheetName)
¤ Exit Sub
¤ End If
¤ wb = xlApp.Workbooks.Open(AnionSpreadsheetName)
¤
¤ Then, because my client uses Excel 2003 I uninstalled Office 2007 and
¤ re-installed Office 2003. Now, on the last line (the call to Open) I get
¤ this error:
¤
¤ Unable to cast COM object of type
¤ 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type
¤ 'Microsoft.Office.Interop.Excel._Application'. This operation failed
¤ because the QueryInterface call on the COM component for the interface
¤ with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the
¤ following error: could not be found. (Exception from HRESULT:
¤ 0x80030002 (STG_E_FILENOTFOUND)).
¤
¤ The file does exist and can be opened manually in Excel 2003, so I am at
¤ a loss.

You're going to have to remove the reference to Excel 2007 from your project and then add the
reference for Excel 2003. I would also delete the Excel interop assembly from your bin folder before
adding the Excel 2003 reference.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
N

Norman Yuan

You app is compiled against Excel2007 PIA. PIA only useful when the
application, from which it is derived, is present. Since you have
uninstalled Excel2007, your app stops working as it should do.

You need to recompile your app against correct targeting version of Excel.

Note, if your app is targeting older version of MS Office app, it may (or
most likely) still work on a computer with newer version MS office app
installed. But not the other way around, in most cases.
 

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