Paul Cook-Giles
asked on
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
and
Neither of them work. Any suggestions?
Application.References.AddFromFile "C:\Program Files (x86)\Common Files\System\ado\msado.tlb"
and
With Excel.Application
.AddFromFile "C:\Program Files (x86)\Common Files\System\ado\msado.tlb"
End With
Neither of them work. Any suggestions?
Why do you need to set a reference in code?
ASKER
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. :)
I don't follow. Why would they need to set the reference themselves? It's saved with the workbook containing the function.
ASKER
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
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
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't use references. Use late binding via the CreateObject() function.
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.
Then replace the object 'set xx = new yy' lines with CreateObject as aikimark notes. Then test again to make sure it works.
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.
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.
ASKER
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
PCG
Thanks for correcting the link but my name is Roy, Rory is another member.