Solved

VB.NET - How to support Excel 2003 and 2007 ?

Posted on 2009-07-13
6
523 Views
Last Modified: 2012-05-07
I am using COM Interop with Excel to import a Tab delimited file and display the data.  This works with both Excel 2003 "OR" 2007.

I am referencing Office 11 library for Excel 2003 and Office 12 for 2007.

How can determine the version on the local PC and then reference the corresponding Office library?

Thanks for any ideas.
0
Comment
Question by:MisterT25
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:rizwanidrees
ID: 24840512
following code will work with all version and you will not need to add any reference

Dim XL as Object
Set XL = CreateObject("Excel.Application")
0
 

Author Comment

by:MisterT25
ID: 24840786
I will try your suggestion and see if that works for me.

Thank you
0
 
LVL 41

Expert Comment

by:graye
ID: 24840826
You can check the registry for either the presence of the Office Primary Interop Assembiles (PIA) or for the Excel application itself
The keys to look for are at HKLM\SOFTWARE\Classes\CLSID

Primary interop assemblies for Office 2003:   {91490409-6000-11D3-8CFE-0150048383C9}

Primary interop assemblies for the 2007 release of Office:  {50120000-1105-0000-0000-0000000FF1CE}
 

Primary interop assembly       Office 2003 component ID               Office 2007 component ID 
Excel                    {A1FE0698-609D-400F-BF10-F52238DD6475}  {1ABEAF09-435F-47D6-9FEB-0AD05D4EF3EA} 
InfoPath                 {C1E59364-35F6-44B3-AF0F-FCA934C4B252}  {F1B5AE30-CB00-4DCF-978B-07D33B034ADB} 
Outlook                  {14D3E42A-A318-4D77-9895-A7EE585EFC3B}  {ED569DB3-58C4-4463-971F-4AAABB6440BD} 
PowerPoint               {3F40FA9E-26CA-4CA2-93C9-603622349915}  {04E73476-518E-4B6A-8E10-021A00078847} 
Visio                    {6F1AE751-4D8A-4B25-AC0A-C6CB912A9791}  {C1F1028F-D91A-43E8-A117-4F7CAFD7A041} 
Word                     {1C8772BD-6E6F-4C9D-8FF8-B5EA072F86EF}  {816D4DFD-FF7B-4C16-8943-EEB07DF989CB} 
Microsoft Forms 2.0*     {835AC3CE-E36B-4D65-B50F-2863A682ABEE}  {835AC3CE-E36B-4D65-B50F-2863A682ABEE} 
Microsoft Graph          {A58B51D1-89BF-4D88-939D-B6D0DB2EEB53}  {580CB155-841D-4D48-9F59-866A035C2241} 
Smart Tag                {53C65973-D89D-4EA0-8567-8788C14E0A02}  {00B41853-4377-4AD8-AD44-8404E0D331EC} 

Open in new window

0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:MisterT25
ID: 24841027
Graye,

Once I check for the PIAs, what do I do next?  Should I use the PIA rather than adding a reference to the Excel object?

Thank you
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 24841327
Well, I'd recommend that you include both the 2003 and 2007 references in your application.... then at runtime, you'd check the registry on the client's PC to see what they've got, then you'd switch to that version.    Consider the following psuedo code
If registry.check(.....2007PIA) then
ex = new Excel2007
else
ex = new Execl2003
endif
0
 

Author Closing Comment

by:MisterT25
ID: 31602856
I get it.  Thank very much for your help !
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now