Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2009-07-13
6
527 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

789 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