Microsoft Office Tutorials and References
In Depth Information
Introducing the Visual Basic Editor
A project may have another node called References. This node contains a list of all
references that the project uses. You can add or remove References by choosing
Tools➜References. Unlike other items listed in the Project window, Reference items
don’t have an associated code module.
Renaming a project
By default, all projects are named VBAProject. In the Project window, the workbook name
appears (in parentheses) next to the project name. For example, a project may appear as follows:
You may prefer to change the name of your project to a more descriptive name. To do so, follow
1. Select the project in the Project window.
2. Make sure that the Properties window is displayed (press F4 if it’s not displayed).
3. Use the Properties window to change the name from VBAProject to something else.
After making the change, the Project window displays the new name.
Adding a new VBA module
A new Excel workbook does not have any VBA modules. To add a VBA module to a project,
select the project’s name in the Project window and choose Insert
When you create custom worksheet functions, they must reside in a standard VBA
module and not in a code window for a Sheet object (for example, Sheet1) or the
ThisWorkbook object. If the code for your custom function does not reside in a VBA
module, it won’t work. Putting VBA code in the wrong place is perhaps the most
common error made by users who are learning to write custom worksheet functions.
Renaming a module
VBA modules have default names, such as Module1, Module2, and so on. To rename a VBA
module, select it in the Project window, and then change the Name property by using the Properties
window. (A VBA module has only one property — Name.) If the Properties window is not visible,
press F4 to display it. Figure 22-8 shows a VBA module named Module1 that is being renamed to