VBA statements are keywords defined in the Visual Basic for Applications specification that make up the VBA language. Statements are used to control program flow, manipulate data, handle errors, communicate with the file system, and act as labels. In contrast, functions primarily return a value or values.
Statement | Action |
---|---|
AppActivate | Activates an application window |
Beep | Sounds a tone through the computer's speaker |
Call | Transfers control to another procedure |
ChDir | Changes the current directory |
ChDrive | Changes the current drive |
Close | Closes a text file |
Const | Declares a constant value |
Date | Sets the current system date |
Declare | Declares a reference to an external procedure in a Dynamic Link Library (DLL) |
DefBool | Sets the default data type to Boolean for variables that begin with specified letters |
DefByte | Sets the default data type to Byte for variables that begin with specified letters |
DefCur | Sets the default data type to Currency for variables that begin with specified letters |
DefDate | Sets the default data type to Date for variables that begin with specified letters |
DefDec | Sets the default data type to Decimal for variables that begin with specified letters |
DefDbl | Sets the default data type to Double for variables that begin with specified letters |
DefInt | Sets the default data type to Integer for variables that begin with specified letters |
DefLng | Sets the default data type to Long for variables that begin with specified letters |
DefLngLng | Sets the default data type to LongLong for variables that begin with specified letters |
DefLngPtr | Sets the default data type to LongPtr for variables that begin with specified letters |
DefObj | Sets the default data type to Object for variables that begin with specified letters |
DefSng | Sets the default data type to Single for variables that begin with specified letters |
DefStr | Sets the default data type to String for variables that begin with specified letters |
DefVar | Sets the default data type to Variant for variables that begin with specified letters |
DeleteSetting | Deletes a section or key setting from an application's entry in the Windows Registry |
Dim | Declares variables and (optionally) their data types |
Do...Loop | Loops through a set of instructions |
End | Used by itself, exits the program; also used to end a block of statements that begin with If, With, Sub, Function, Property, Type, or Select |
Enum | Declares a type for enumeration |
Erase | Reinitializes an array |
Error | Simulates a specific error condition |
Event | Declares a user-defined event |
Exit Do | Exits a block of Do-Loop code |
Exit For | Exits a block of For-Next code |
Exit Function | Exits a Function procedure |
Exit Property | Exits a property procedure |
Exit Sub | Exits a subroutine procedure |
FileCopy | Copies a file |
For Each...Next | Loops through a set of instructions for each member of a series |
For...Next | Loops through a set of instructions a specific number of times |
Function | Declares the name and arguments for a Function procedure |
Get | Reads data from a text file |
GoSub...Return | Branches to and returns from a procedure |
GoTo | Branches to a specified statement within a procedure |
If...Then...Else | Processes statements conditionally |
Implements | Specifies an interface or class that will be implemented in a class module |
Input # | Reads data from a sequential text file |
Kill | Deletes a file from a disk |
Let | Assigns the value of an expression to a variable or property |
Line Input # | Reads a line of data from a sequential text file |
Load | Loads an object but doesn't show it |
Lock, Unlocks | Controls access to a text file |
LSet | Left-aligns a string within a string variable |
Mid | Replaces characters in a string with other characters |
MkDir | Creates a new directory |
Name | Renames a file or directory |
On Error | Gives specific instructions for what to do in the case of an error |
On...GoSubs | Branches, based on a condition |
On...GoTos | Branches, based on a condition |
Open | Opens a text file |
Option Base | Sets the default lower limit for arrays |
Option Compare | Declares the default comparison mode when comparing strings |
Option Explicit | Forces declaration of all variables in a module |
Option Private | Indicates that an entire module is Private |
Print # | Writes data to a sequential file |
Private | Declares a local variable |
Property Get | Declares the name and arguments of a Property Get procedure |
Property Let | Declares the name and arguments of a Property Let procedure |
Property Set | Declares the name and arguments of a Property Set procedure |
Public | Declares a public variable |
Put | Writes a variable to a text file |
RaiseEvent | Fires a user-defined event |
Randomize | Initializes the random number generator |
ReDim | Changes the dimensions of an array |
Rem | Specifies a line of comments (same as an apostrophe [']) |
Reset | Closes all open text files |
Resume | Resumes execution when an error-handling routine finishes |
RmDir | Removes an empty directory |
RSet | Right-aligns a string within a string variable |
SaveSetting | Saves or creates an application entry in the Windows Registry |
Seek | Sets the position for the next access in a text file |
Select Case | Processes statements conditionally |
SendKeys | Sends keystrokes to the active window |
Set | Assigns an object reference to a variable or property |
SetAttr | Changes attribute information for a file |
Static | Declares variables at the procedure level so that the variables retain their values as long as the code is running |
Stop | Pauses the program |
Sub | Declares the name and arguments of a Sub procedure |
Time | Sets the system time |
Type | Defines a custom data type |
Unload | Removes an object from memory |
While...Wend | Loops through a set of instructions as long as a certain condition remains true |
Width # | Sets the output line width of a text file |
With | Sets a series of properties for an object |
Write # | Writes data to a sequential text file |