Home > Common Problem > body text

What are the naming rules for vba variable names?

coldplay.xixi
Release: 2020-10-29 16:11:36
Original
10446 people have browsed it

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!