Adding modules to the library

Most programmers at some point start collecting modules containing solutions they previously used succesfully, with the purpose of later using them again. Code VBA provides a library feature which makes it possible to save your modules in an organized way.

Code modules may contain one or more procedures that can function independently. Some solutions however require a combination of modules and een code snippets.

snippets appear as part of main menu

Adding a single module

To add a module in your current project to the library:

  1. Clean up the module so that it has a clearly defined purpose and only contains procedures for that;
  2. Give the module a suitable name;
  3. In the Code Explorer right-click the module to export and select 'Export file';
  4. Chosing a location in the \VBA Code folder most suitable to store the module.

Example: modStringFunctions

A collection of common String manipulation functions is in the \VBA\String subfolder of the Code VBA library. As such, it functions are accessible from the VBA » String menu.

The VBA Strings Library menu shows all available String related snippets and procedures
The VBA Strings Library menu shows all available String related snippets and procedures

Looking at the tooltip of the procedure StringContains we see a title that indicates what behaviour we may expect.

Procedures that operate on Objects

The image below, showing the Code Library folder hierarchy, the folder of Workbook is opened. The right pane shows which modules are inside. It seems logical to have modWorkbookFindProcedures or modRangeNameProcedures in there, containing procedures related to Finding (ranges). But why is modSheetIsProcedures in this folder, and not in folder \Worksheet? The reason is the modules contains procedures, such as IsValidSheetName, that don't work on a Worksheet object, but are useful in the context of a Workbook object.

Chosing a location to store a module

The Code VBA library already has a structure reflecting VBA and Office application's Objects. We suggest you follow this design, when adding modules.

Code Library folder hierarchy
Code Library folder hierarchy