Creating a DLL that Acts as a Code Library
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
DLLs make ideal code libraries because they are small and fast. The disadvantage to using a DLL is that you must make certain it is properly registered on the user's machine.
To create a DLL that acts as a code library
- Create a new DLL project in Microsoft® Visual Basic®.
- Create a new class module in the project.
- Set the class module's Instancing property to GlobalMultiUse. This ensures that your procedures will be visible to any project that wants to use them and that they will behave as global procedures.
- Set references to any object libraries required by your code.
- Add the procedures you want in your code library to the class module as public Function and Sub procedures.
- Change the project's name to the name you want for your code library by clicking Properties on the Project menu and entering a new value for the Project Name property.
- Make the DLL.
To use the code library from a VBA project, set a reference to the DLL. To set a reference to a DLL, click References on the Tools menu, and use the Browse button to locate the DLL. After the reference has been added, the Object Browser will display information about the procedures in the code library.
If your code library is large, you might not want to load it with your project. Rather than setting a reference to the DLL, you can use the Declare statement to declare references to individual procedures in the DLL.