3.6.7 Naming Macros

Observe the following rules when you name Visual Basic macros (including procedures, constants, variables, and arguments):

  • Use a letter as the first character. (Names aren't case sensitive, but they preserve capitalization.)

  • Use only alphanumeric characters and the underscore character ( _ ). Spaces and other symbols are not allowed.

  • Use fewer than 255 characters.

  • Avoid names that match Visual Basic or Reflection commands. Or, if you do use a macro name that is the same as a command, fully qualify the command when you want to use it. (To do this, you need to precede the command name with the name of the associated type library. For example, if you had a macro named Beep, you could only invoke the Visual Basic Beep statement using VBA.Beep.)

  • Give unique names to macros within a single module. Visual Basic doesn't allow you to have two macros with the same name in the same code module. However, you can have two macros with the same name if they are in different code modules. For example, although you could not have two macros named StartUp in the same code module, you could have two macros named StartUp if they were in different code modules. To call a macro with a duplicate name that is in another code module, you must fully qualify the macro name. (For example, Module1.StartUp invokes the StartUp macro in Module1.)