How to add Microsoft ActiveX Data Objects 6.1 Library and Microsoft VBScript Regular Expressions 5.5 using macro code
I always added references into my .bas module through "Tools...->References...". And now I want to add references automatically, using macro code. I need to add the two references: Microsoft ActiveX Data Objects 6.1 Library and Microsoft VBScript Regular Expressions 5.5. And I found a piece of code that seems to do what I want:
On Error GoTo CanNotAddReferences
MsgBox "Can not add reference"
But I don't know how to get paths of files (PATH_TO_FILE). Maybe somebody can help me? Thanks in advance.
You can find the file path on the References VBAProject dialog (Tools >> References). Look for the location property.
EDIT: As pointed out in the comments, you cannot always read the full name. This sub outputs all the current references.
' Displays all current refernce names and full paths.
Dim ref As Object
For Each ref In Application.VBE.ActiveVBProject.References
MsgBox "Name: " & ref.Name & vbCrLf & ref.FullPath
You should really read @MacroMan's comment on the OP. Although you can update references programmatically, you probably shouldn't.
Asked in February 2016Viewed 1,608 timesVoted 14Answered 1 times