ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help! Problem Referencing Excel 2003 in VB.NET (https://www.excelbanter.com/excel-programming/438173-help-problem-referencing-excel-2003-vbulletin-net.html)

Alan[_8_]

Help! Problem Referencing Excel 2003 in VB.NET
 
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




Alan[_8_]

Help! Problem Referencing Excel 2003 in VB.NET
 
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?


All times are GMT +1. The time now is 10:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com