Home Common Problem What are the naming rules for vba variable names?

What are the naming rules for vba variable names?

Oct 27, 2020 am 11:23 AM

VBA variable name naming rules: 1. The first character must be a letter; 2. The name can contain letters, numbers, and underscores; 3. The name cannot contain spaces, periods, exclamation points, or characters. [@, &, $ and #]; 4. The name can contain up to 255 characters.

What are the naming rules for vba variable names?

VBA variable name naming rules:

1. VBA has the following naming rules for subroutines and functions:

1) The first character must be a letter.

2) The name can contain letters, numbers and underscores.

3) The name cannot contain spaces, periods, exclamation points, or the characters @, &, $, and #.

4) The name can contain up to 255 characters.

2. Variable type

Variables are used to save process data. Below are the variable types used in VBA. The naming rules for variable names are the same as for procedure names. The definition of variables uses Dim variable name as data type

3. Variable declaration

The following will create a process whose function is to prompt the user to enter a name and then display it in the message box.

Public Sub KnowYourName()
Dims Name As String
sName = InputBox("Enteryourname:")
MsgBox "Hi"&sName
End Sub
Copy after login

Where Name is a string variable, there is no need to provide a data type in the Dim statement. If no data type is provided, the variable will be assigned the default data type in VBA, Variant. If the data type is not defined, it will take up space and increase the running time.

Dim iNumberOfStudents as Integer
Dim dTestDate as Date
'The following line creates a variable length string
Dim sLastName as String
'The next line creates a 2char. Fixed length string
Dim sState as String*2
Copy after login

You can add comments by starting with a single quote

The above is the detailed content of What are the naming rules for vba variable names?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1258
29
C# Tutorial
1232
24