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 8
Paul Cook-GilesSenior Application DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rory ArchibaldCommented:
Why do you need to set a reference in code?
0
Paul Cook-GilesSenior Application 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
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
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Paul Cook-GilesSenior Application 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
NorieAnalyst Assistant Commented:
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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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-GilesSenior Application 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.