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:
Microsoft ActiveX Data Objects (ADO) enable your client applications to access and manipulate data from a variety of sources through an OLE DB provider. Its primary benefits are ease of use, high speed, low memory overhead, and a small disk footprint.
But I don't know how to get paths of files (PATH_TO_FILE
). Maybe somebody can help me? Thanks in advance.
1 Answer
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.
Warning
You should really read @MacroMan's comment on the OP. Although you can update references programmatically, you probably shouldn't.
destination-datadestination-dataNot the answer you're looking for? Browse other questions tagged vbaexcel-vbaexcel or ask your own question.
-->To import the ADO libraries into a Microsoft Visual Basic 6 application, you must set a reference in the Visual Basic project.
To set a reference to the ADO libraries in a Visual Basic project
Create a new or open an existing Visual Basic project.
Click the Project menu item and then select References... from the drop-down menu panel.
From Available References, check the box for Microsoft ActiveX Data Objects n.n Library, where n.n represents the latest version number. The Location field below should identify your choice as $installDirmsado15.dll, where $installDir represents the path of the directory in which the ADO library has been installed.
If you intend to use ADO MD, repeat step 3 to select Microsoft ActiveX Data Objects (Multi-dimensional) n.n Library. The Location field should identify this choice as $installDirmsadomd.dll.
If you intend to use ADOX, repeat step 3 to select Microsoft ADO Ext. n.n for DDL and Security. The Location field should identify this choice as $installDirmsadox.dll.
Click OK to finish setting the references.
Backward Compatibility
Activex Data Objects Download
Installing ADO also copies the following type libraries of earlier versions:
msado27.tlb, ADO 2.7 Type Library
msado26.tlb, ADO 2.6 Type Library
msado25.tlb, ADO 2.5 Type Library
msado21.tlb, ADO 2.1 Type Library
msado20.tlb, ADO 2.0 Type Library
Install Microsoft Activex Data Objects 2.7 Library
If your application must use any of these ADO libraries for reasons of backward compatibility, you need to import the appropriate version of the type library. To do this, follow the procedures in the previous section, replacing msado15.dll by msadoXX.tlb, where XX represents the version number you need to import.