Microsoft Office Tutorials and References
In Depth Information
Understanding VBA Syntax
The first comma after the “Howdy” prompt shows the start of the second
argument. No argument appears between the two commas, because you’re
not using an argument there. The second comma shows that the next
argument, Title (hence, the text “I am the Title” appears in the title bar of
the message box), is actually the third one. Because no value is provided for
the Buttons argument, the box shows only the default OK button.
Knowing module level from procedure level
As you work with the VBA help windows and syntax charts, you often come
across the terms module level and procedure level. These terms refer to the
location of code within the module. Simply stated, anything that’s defined
near the top of the module above the first Function or Sub procedure is a
module-level declaration. Anything defined within a procedure is said to be a
procedure-level declaration, as illustrated in Figure 2-7.
All procedures that you add to a module should be placed below the
declarations section of the module. When you see one or more Option statements
at the top of a module, make sure that any procedures you add to the
module start below all the Option statements at the top of the module.
Declaring module options
When you create a new standard module, it has just one declaration at the
top. Typically, that declaration reads Option Compare Database, which
doesn’t seem to make any sense, and frankly, changing or deleting it is
extremely unlikely. The declaration actually has meaning, however:
✦ Option: The word Option tells the VBA to set an option. The specific
option to set is the Compare option (covered next).
✦ Compare: The Compare option tells VBA what rules to use when