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

Problem Adding Reference to Excel Primary Interop Assembly

Status
Not open for further replies.

DaveInIowa

Programmer
Dec 2, 2003
576
US
When I add a reference to COM component [blue]Microsoft Excel 11.0 Object Library[/blue], the reference added is [blue]Copy Local=True[/blue] to [blue]Interop.Excel.dll[/blue] (Version 1.5.0.0) in my Release folder. Does anybody know how to get it to reference the copy in the Global Assembly Cache? I can change the Copy Local property but I'm not able to change the Path property to the GAC.

I have Office 2003 installed and I am able to see [blue]Microsoft.Office.Interop.Excel[/blue] (Version 11.0.0.0) in my WINDOWS\assembly folder.
 
Don't add it as a reference. Then to deal with it as an object:
Code:
Dim objExcel As Object
objExcel = CreateObject("Excel.Application")

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Sorwen - Thank you for taking the time to respond, but I'd really like to know how to get this reference added so I am not late binding and have access to the Excel object model and the Intellisense features that come with it.
 
I believe what Sorwen tried to say is changing
Code:
Dim objExcel As Excel.Application
objExcel = New Excel.Application
to
Code:
Dim objExcel As Object
objExcel = CreateObject("Excel.Application")

Every single statement related to Excel object should be treated that way.

Regards.
 
The only other thing I can suggest is see if it works if you exclude it from your setup, but I don't know that will work. As far as I know though there is no way to do it though. When you add a reference at design it expects that reference to be included.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
FYI Copy Local (vs2005 at least) just means that after the reference is added either True it will only use the copy that was saved to the local folder when it was set to true or False it will always get the reference from the location it was added from.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Actually, thinking about it, it may add the reference when it is built after the CL is set to true not when you set it to true. Either way the that is what the True/False means.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Thanks to all for taking the time to respond. Just for kicks, I added the following references to a new project to see what the Copy Local and Path properties were:
[ul square]
[li]Microsoft Office 11.0 Object Library[/li]
[li]Microsoft Outlook 11.0 Object Library[/li]
[li]Microsoft Word 11.0 Object Library[/li]
[/ul]
Both Outlook and Word are correctly referencing the assembly in the GAC (with Copy Local=False). Microsoft Office, which was added automatically, exhibits the same behavior as the Excel assembly.

I checked the VS Options but didn't see anything. Any ideas on whether this could be a Registry setting?
 
I had a system admin reinstall the PIAs and am now getting the correct references. I believe the problem was that the assemblies were installed in the GAC but were not registered. I still don't have any idea where it was finding the .dll for the local copy, but everything seems to be working now.
 
I think a few things got confused. If you set your Microsoft Excel 11.0 Object Library reference to Copy Local = False then it is going to use what is installed on your computer (GAC) when you run it. It will still show up in your Release folder because it placed a copy when it was first built (or whenever). If it will not let you set Copy Local to false I would assume that it is a flaw in 2003 as in 2k5/8 you can.

The state of the local copy means nothing unless you updated office and it installed a new version of Microsoft Excel Object Library at which time you likely would have to update your program as well. This also means nothing if your are installing this on other computers.

What I originally told you would allow you to ignore all of that. No matter what when you create an object in that manner then it will use the most current installed on whichever computer it is currently running on. The only requirement is that it is installed. But then yes you have to do late binding with no Intellisense.

Sorry I didn't think to explain that to begin with.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top