Microsoft Office Tutorials and References
In Depth Information
Understanding VBA Syntax
Figure 2-1:
Code
execution
from top to
bottom.
You can alter the top-to-bottom flow of execution by using loops and
decision-making code, as we describe in Chapter 3 of this minibook.
Understanding VBA Syntax
You can’t just write text that looks like VBA code. Like all languages,
including English, VBA has strict rules of syntax, and each statement within a
procedure must follow those rules. Syntax defines the order in which words
must be placed so that a statement makes sense. The following sentence —
which is English, by the way, and not VBA — doesn’t make sense because
grammar rules are broken (similar to the way that they’re mangled in some
of those e-mails we get):
moon the yapped sullen dog at irritating the.
If we rearrange the letters and words of that sentence so that they follow the
correct rules of syntax for the English language, the sentence makes sense:
The irritating dog yapped at the sullen moon.
The rules of VBA syntax are more rigid than the rules of human language.
Even the slightest misspelling or missing punctuation mark causes a
statement to fail.
Most statements start with a keyword, which is a word that has a specific
meaning in VBA. As soon as you type a complete keyword followed by a
space, you typically see a brief Quick Info syntax chart for the keyword.
Figure 2-2 shows an example. If you don’t see the syntax chart, you can
rightclick the keywords and choose Quick Info from the contextual menu.
 
Search JabSto ::




Custom Search