Microsoft Office Tutorials and References
In Depth Information
Application Level
figurE 6-5
Application level
Finally, you can declare the variables as Public , which will make them visible to all macros in all
modules. You only need to place the statements at the top of one standard module, like so:
Public intAdd As Integer
Public intSum As Integer
A variable’s value may often change during a macro’s execution, but some macros are better served
with a reference to a particular value that will not change. A constant is a value in your macro that
does not change while the macro is running. Essentially, constants are variables that do not change.
When you declare a constant, you do so by entering a declaration statement that starts with the
Const statement, followed by the constant’s name you specify, then the data type, and finally the
value, all on one line. Here is an example:
Const myMonths as Integer = 12
It’s a good practice to use constants for the same reasons you would use a variable. Instead of
hardcoding the same value in your macro over and over, you define the constant just once and use the
reference as you need to. For example, your macro may be analyzing the company’s sales amounts,
and needing to factor in the sales tax at various points in the macro. This constant statement at the
start of the macro would allow you to reference the 8.25% sales tax:
Const SalesTax as Double = .0825
Search JabSto ::

Custom Search