Help! Problem Referencing Excel 2003 in VB.NET

A

Alan

I am using Visual Studio 2008 Express Edition to develop some VB.NET
code that manipulates Excel files. I am developing on a Vista/Excel
2007 machine, but I need the code to work on an XP/2003 machine as
well.

I initially set a reference to the Microsoft Excel 12.0 Object Library
and imported the Microsoft.Office.Interop.Excel namespace. This works
great on the VIsta/Excel 2007 machine, but it does not work on 2003,
which needs the 11.0 library. I get an error that says "Unhandled
Exception . . . Could not file or assembly
'Microsoft.Office.Interop.Excel, Version 12.0.0.0 . . . The system
cannot find the file specified."

I searched through the other references I could find. I found nothing
for 11.0, but there was an Excel 5.0 Object Library. When I add this
and remove the Excel 12 library reference, it no longer works on
Vista.

What can I do to make this work on both Excel 2003 and 2007 without
having to compile on a machine with 2003?

Thanks, Alan
 
A

Alan

I changed the reference to Excel 5.0 only and now only Import Excel.
I changed starting an instance of Excel to:

ExcelApp = CreateObject("Excel.Application")

The following code cannot open the workbook:

If FileExists(PathName) Then
MetaWB = ExcelApp.Workbooks.Open(PathName)

It finds that the file exists, but then the workbook cannot be opened:

A first chance exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Any ideas?
 

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