Databases Reference
In-Depth Information
Sub Example1()
A = 100
B = A + 1
End Sub
Sub Example2()
MsgBox "The value of A is " & A
MsgBox "The value of B is " & B
End Sub
Sub Example3()
Dim C As Integer' Local variable.
C = A + B
MsgBox "The value of C is " & C
End Sub
Sub Example4()
MsgBox A
' The message box displays the value of A. MsgBox B
' The message box displays the value of B. MsgBox C
' The message box displays nothing because C was a local
variable.
End Sub
F.2.3
P
S
UBLIC
COPE
Public variables have the broadest scope of all variables. A public variable is recognized by
every module in the active workbook. To make a public variable available to other workbooks,
from a new workbook select the workbook containing the public variable in the Available
References box of the References dialog box (from a module sheet, click
References
on the
Tools
menu). A public variable, like a module-level variable, is declared at the top of the module,
above the first procedure definition. A public variable cannot be declared within a procedure. A
public variable is always declared with a “Public” statement. A public variable may be declared
in any module sheet.
It is possible for multiple module sheets to have public variables with the same name. To avoid
confusion and possible errors, it is a good idea to use unique names or to precede each variable
name with a module qualifier (for example, in a module named “Feb_Sales” you may want to
precede all public variables with the letters “FS”). To create the macros:
1.
Create a new workbook and name it CDSales.xls.
2.
In the
.
In Microsoft Excel 97 or later follow these steps to insert a new module sheet and name
the module sheet:
a. In the
CDSales.xls
workbook, insert a module sheet. Name the module sheet
CDSales
CDSales.xls
workbook, point to
Macro
on the
Tools
menu, and then click
Visual Basic Editor
.
b. On the
.
c. In Microsoft Excel for Windows (version 97 and later), you can rename a module
by activating the module, clicking to the right of “(Name)” in the
Insert
menu, click
Module
Properties
window of the Visual Basic Editor, type a new module name, and then press
ENTER.
Search WWH ::




Custom Search