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

Accomodating several Excel Versions (Development and Production)

Status
Not open for further replies.

Goodall

MIS
Aug 4, 2004
18
US
I am using Microsoft Excel 2003 on my computer in development. I added the COM reference for "Microsoft Excel 11.0 Object Library". Via VB .NET 2003 I create and Excel file without a hitch. My users have Excel 2003 and possibly earlier. I have no problem creating the Excel files but they get the error that says "File or assembly name Microsoft.Office.Interop.Excel, or one of its dependencies, was not found". What seems to be the problem and how might I correct it? Thanks.
 
A major correction on my previous post. My users have Excel 2000 or earlier. They do NOT have Excel 2003.
 
Because the different versions of Excel have different libraries, this sounds like a good place to apply a pattern.

You can choose between a Factory, a Facade, or a Plugin pattern, depending on how you intend to use/access Excel.

Facade:
Factory:
Plugin:

The basic idea behind all of them is that you put the version-dependent code off in it's own module, which other code can then access via a generic programming API (typically done via an Interface).

So, if you need a way to get the contents of a cell, you create a GetCellValue method in your Interface, then implement that interface in your Excel2k, Excel 2k3, and Excel95 DLLs. You load the correct DLL by finding out what version they have installed (inspecting the registry, most likely). If you decide to support Excel 4 (or some other version) all you have to do is write a new DLL that implements your interface, then change the code that decides which DLL to load.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Late-Binding was the solution. Here is what I did.

1) Removed the Excel COM reference via the Solution Explorer

2) Commented out the prior declarations and replaced them as follows:
Code:
'Dim xlApp As Microsoft.Office.Interop.Excel.Application
'Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
'Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim xlApp As Object
Dim xlBook As Object
Dim xlsheet As Object

3) Commented out the prior object "creations" and replaced them as follows:
Code:
'xlApp = CType(CreateObject("Excel.Application"),Excel.Application)
'xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)
'xlsheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.workbooks.add()
xlsheet = xlBook.Worksheets(1)

4) To save the workbook I used this code:
Code:
xlBook.SaveAs("C:\" & FileName & FileExtension)

Now machines with Excel 2000 and Excel 2003 will both create the Excel document in the appropriate version.

The downside with this approach is that the Excel object model is not "exposed" during the development process so I develop using early-binding and change over to late-binding when I want to promote the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top