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

  1. Create a new DLL project in Microsoft® Visual Basic®.
  2. Create a new class module in the project.
  3. 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.
  4. Set references to any object libraries required by your code.
  5. Add the procedures you want in your code library to the class module as public Function and Sub procedures.
  6. 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.
  7. 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.

See Also

Building Reusable Code Libraries | Creating an Application-Specific Template or Add-in That Acts as a Code Library | Sharing Code with the Code Librarian