Microsoft Office Tutorials and References
In Depth Information
Chapter 8: VBA Programming Fundamentals
VBA Programming
In This Chapter
Understanding VBA language elements, including variables, data types, constants, and
Using VBA built-in functions
Manipulating objects and collections
Controlling the execution of your procedures
VBA Language Elements: An Overview
If you’ve used other programming languages, much of the information in this chapter may sound
familiar. However, VBA has a few unique wrinkles, so even experienced programmers may find
some new information.
In Chapter 7, I present an overview of objects, properties, and methods, but I don’t tell you much
about how to manipulate objects so that they do meaningful things. This chapter gently nudges
you in that direction by exploring the VBA language elements, which are the keywords and
control structures that you use to write VBA routines.
To get the ball rolling, I start by presenting a simple VBA Sub procedure. The following code,
which is stored in a VBA module, calculates the sum of the first 100 positive integers. When the
code finishes executing, the procedure displays a message with the result.
Sub VBA_Demo()
‘ This is a simple VBA Example
Dim Total As Long, i As Long
Total = 0
For i = 1 To 100
Search JabSto ::

Custom Search