Table of contents
TOC
Collapse the table of content
Expand the table of content

Visual Basic Naming Rules

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Use the following rules when you name procedures, constants, variables, and arguments in a Visual Basicmodule:

  • You must use a letter as the first character.

  • You can't use a space, period ( . ), exclamation mark ( ! ), or the characters @, &;, $, # in the name.

  • Name can't exceed 255 characters in length.

  • Generally, you shouldn't use any names that are the same as the functions, statements, and methods in Visual Basic. You end up shadowing the samekeywords in the language. To use an intrinsic language function, statement, or method that conflicts with an assigned name, you must explicitly identify it. Precede the intrinsic function, statement, or method name with the name of the associatedtype library. For example, if you have a variable called Left, you can only invoke the Left function using VBA.Left.

  • You can't repeat names within the same level of scope. For example, you can't declare two variables named age within the same procedure. However, you can declare a private variable named age and aprocedure-level variable named age within the same module.

    Note Visual Basic isn't case-sensitive, but it preserves the capitalization in the statement where the name is declared.

© 2018 Microsoft