Show Contents / Index / Search

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 have a macro called Beep, you can only invoke the Visual Basic Beep statement by using VBA.Beep.
  • Give unique names to macros within a single module. Visual Basic doesn't allow you to have two macros named StartUp in the same code module. However, you can have two macros named StartUp if they are 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.