Microsoft Office Tutorials and References
In Depth Information
Chapter 3: Writing Smarter Code
Chapter 3: Writing Smarter Code
In This Chapter
Using variables and constants to store temporary data
Having your code make decisions
Executing code over and over
Managing data with custom VBA functions
Like all programming languages, Visual Basic for Applications (VBA)
offers certain concepts and statements designed to allow you to write
the code necessary to make a computer do — well, anything. Those
concepts and statements are the subject of this chapter.
We must point out, though, that the underlying VBA concepts described in
this chapter aren’t unique to VBA. Virtually all programming languages are
built around these same concepts. If you aspire to know how to program in
any language — Java, JavaScript, C++, C#, VBScript, or whatever — the
concepts that you discover in this chapter apply equally to most programming
Creating Variables and Constants
Within a procedure, you define and use variables. A variable is a name — a
placeholder — for any data that may change. You make up your own variable
names. Choose names that indicate what information the variables contain
so you don’t have to wonder later.
A variable name must begin with a letter, can’t contain spaces or punctuation,
and can’t be the same as any built-in keyword.
Unlike data stored in a table, data stored in a variable isn’t permanent. Data
stored in a variable is fleeting and exists for only as long as VBA needs the
information contained within the variable.
Creating variables
You can create variables in VBA code in a couple of ways: create them on
the fly or define them in advance.
Search JabSto ::

Custom Search