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

Programmatically adding references

Status
Not open for further replies.

rguglielmon

Technical User
Jan 6, 2003
12
0
0
US
I want to create an Excel Add-In that references the Access and ADO libraries. I'd like to avoid having the user manually add these references. From the Help documentation it looks like I can use the References collection to add references by GUID. I tried to play around with this by looping thru the references collection like this:
Dim i
For i = 1 To References.Count
Debug.Print References(i).Name
Debug.Print References(i).GUID
Debug.Print "------------------------"
Next i

and like this:

Dim Ref
For Each Ref In References
Debug.Print Ref.Name
Debug.Print Ref.GUID
Debug.Print "------------------------"
Next Ref

In each case, I get an error message "You made an illegal function call" on the For statement. What am I doing wrong or not understanding?
 
Hi rguglielmon,


Better to post VBA questions in the VBA Forum, but as I'm here ..

To access the References, use [blue][tt]ThisWorkbook.VBProject.References[/tt][/blue] instead of just [purple][tt]References[/tt][/purple]. Also note that you'll need a reference to the VBA Extensibility library.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top