Code Attributes For The VBA Object Browser
This page describes how to annotate code to provide
information for the Object Browser.
There is a bit more to VBA code and class modules that meets the eye. Code modules and
class modules contain "Attribute" statements that provide information about the module
and the procedures within the module. These Attribute statements are created by the
VBA editor and are not visible or available to modify within the VBA editor. However,
you can add your own
attributes via a text editor such as Notepad and provide information that will display
in the Object Browser.
All of the methods presented on this page require you to export the module from VBA to a
text file, modify that text file, and then import the text file back into VBA. To export
a module, select that module in the Project window (press CTRL R to
view this window if it is not already visible, typically on the left side of the screen), go
to the File menu and choose Export File. That will display a simple Windows
Save As dialog. Navigate to the folder in which you want to save the text file and click OK.
Next, open NotePad (from the Windows Start menu, choose Run and enter
NotePad.exe). In NotePad, open the text file that you exported from VBA. Class modules
will have an extension of cls and module files will have an extension
of bas. You'll need to change the default file type in the
Open dialog from "Text Files *.txt" to "All Files *.*". Once you have modified the text files, as
described below, save the file from within NotePad and then close NotePad. (As an
alternative to NotePad,
you can use your favorite text editor, but don't use any program, such as Word, that will change
the file format.) To import the file in VBA, you first need to remove the existing module. Select
that module from the Project window and then choose Remove module from the File menu in VBA.
Then, on the File menu, choose Import File and navigate to and select the file you just
modified in NotePad.
You can add a description to a code or class module. This text will appear in the Object Browser. For example,
if you added the VB_Description attribute to Module1, that description
will show in the Object Browser when you select Module1 in the Classes list. The image
below illustrates the description attribute for Module1 with a value of This is Module1.
To add a description to a module, open the module in NotePad and add the following string to the top of the
module, after any Attribte statements that are already there.
Attribute VB_Description = "This is Module1"
Note that there must be a space before and after the '=' character.
You can add a description to individual procedures within a code or class module and these description will be displayed when
the procedure is selected in the Object Browser. For example, the following image show that a description attribute has
been added to the procedure named SomeProcedure:
To add a description to a procedure within a module, open that module in NotePad and add the following line
immediately after the procedure's declaration:
Attribute SomeProcedure.VB_Description = "SomeProcedure does something cool."
Change the SomeProcedure to the name of the procedure. Note that there must be a space before
and after the '=' character.
|
This page last updated: 16-December-2008. |