Export (0) Print
Expand All

Writing Declaration Statements

Office 2007

You use declaration statements to name and define procedures, variables, arrays, and constants. When you declare a procedure, variable, or constant, you also define its scope, depending on where you place the declaration and what keywords you use to declare it.

The following example contains three declarations.

Sub ApplyFormat()
    Const limit As Integer = 33
    Dim myCell As Range
    ' More statements
End Sub

The Sub statement (with matching End Sub statement) declares a procedure named

. All the statements enclosed by the Sub and End Sub statements are executed whenever the
procedure is called or run.

The Const statement declares the constant

specifying the Integer data type and a value of 33.

The Dim statement declares the variable

. The data type is an object, in this case, a Microsoft Excel Range object. You can declare a variable to be any object that is exposed in the application you are using. Dim statements are one type of statement used to declare variables. Other keywords used in declarations are ReDim, Static, Public, Private, and Const.

Community Additions

© 2014 Microsoft