Article / Updated 01-10-2022
The following table provides a list of commonly used VBA statements that you might use when creating macros for Excel. For more information on a particular statement, consult Excel’s Help system.
VBA Statement
What It Does
AppActivate
Activates an application window
Beep
Sounds a tone via 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)
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
Erase
Re-initializes an array
Error
Simulates a specific error condition
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
collection
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.