Building Reusable Code Libraries
After you have been writing Microsoft® Visual Basic® for Applications (VBA) code for any length of time, you will find you must perform certain operations regularly. For example, you often might have to parse a file path and return just the name of the file, or you might have to write procedures to log errors to a text file. Rather than re-creating these procedures each time you must use them, you can store them in a code library and reuse them in other VBA projects.
There are two ways that you can create a reusable code library programmatically:
- By creating a DLL in Visual Basic 4.0 or later
- By creating an application-specific template or add-in
Whatever method you choose, you must always set a reference from the VBA project to the file containing the code library. Even if the file is a template or add-in, the procedures it contains will not be available to your VBA project unless you set a reference to it. When you do set a reference to a code library, you can call its procedures from your VBA project.
In This Section
- Creating a DLL that Acts as a Code Library
Share code programmatically using DLL files. - Creating an Application-Specific Template or Add-in That Acts as a Code Library
Share code using alternate methods, such as storing code in a template or add-in.
Related Sections
- Sharing Code with the Code Librarian
You can increase your productivity by storing and managing reusable code in a centralized database.