Need to set reference with Excel VBA

I need to set a reference to a library (Microsoft ActiveX Data Objects 2.6 Library) with VBA.  I've tried
Application.References.AddFromFile "C:\Program Files (x86)\Common Files\System\ado\msado.tlb"

Open in new window


and
With Excel.Application
    .AddFromFile "C:\Program Files (x86)\Common Files\System\ado\msado.tlb"
End With

Open in new window


Neither of them work.  Any suggestions?
LVL 6
Paul Cook-GilesAccess/VBA/SQL Database DeveloperAsked:
Who is Participating?
 
Roy CoxGroup Finance ManagerCommented:
If you want to distribute the Function then place it in a workbook and set the refernces manually. Then save the workbook as an addin which is what you distribute

Additional Info:
Create and install addins

Deploying Addins in a Network
0
 
Rory ArchibaldCommented:
Why do you need to set a reference in code?
0
 
Paul Cook-GilesAccess/VBA/SQL Database DeveloperAuthor Commented:
Because I'm releasing a function into the production environment that requires it, and I don't want to try coaching 55 people through setting the reference manually.  :)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Rory ArchibaldCommented:
I don't follow. Why would they need to set the reference themselves? It's saved with the workbook containing the function.
0
 
Paul Cook-GilesAccess/VBA/SQL Database DeveloperAuthor Commented:
Hm.  Then maybe I'm asking the wrong question (this is the first time I've written an Excel function).  

Maybe I should be asking "What's the best way to distribute a new Excel function, which requires a reference (to Microsoft ActiveX Data Objects 2.6 Library),  to a non-technical user group?"  Ideally, they would have access to the new function in every spreadsheet they edit, new or pre-existing.

Paul
0
 
NorieVBA ExpertCommented:
What does the code you want to distribute do?

What references does it require?

Have you considered using late binding?

PS Are the people who will be using this code all on the same version(s) of Excel/Office etc?
0
 
aikimarkCommented:
Don't use references.  Use late binding via the CreateObject() function.
0
 
Robberbaron (robr)Commented:
I do my development with References set.

Then replace the object 'set xx = new yy' lines with CreateObject as aikimark notes.  Then test again to make sure it works.
0
 
Ken ButtersCommented:
I have a workbook I distribute to our group all the time.  That workbook happens to use the reference you mentioned, as well as several others.

When one of my team members picks up that workbook, they do not have to set references, it is already part of the workbook. -- I think this is the same thing that Rory mentioned above.
0
 
Paul Cook-GilesAccess/VBA/SQL Database DeveloperAuthor Commented:
Thanks, everyone!  Rory, I think you may have provided the solution;  let me test it out and I'll be back to update this question.  (Note that the url for your first link should be http://excel-it.com/excel-addins.html)

PCG
0
 
Roy CoxGroup Finance ManagerCommented:
Thanks for correcting the link but my name is Roy, Rory is another member.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.