Professional Documents
Culture Documents
Outline
Object-Oriented
Programming
The
Basic of Visual Basic for
Application (VBA)
Introducing the Visual Basic Editor
(VBE)
Exercises (ActiveObject, ActiveForm,
and
With-End
With
instruction
construct)
Object-Oriented Programming
(OOP)
In
Object
2
data
Object
3
data
data
1.
2.
3.
4.
About VBA
VBA
is a programming language
based on objects.
Visual Basic is the foundation on which
VBA was built.
The secret to using VBA with other
applications lies in understanding the
object model for each application.
VBA, after all, simply manipulates
objects.
Beginner's All-purpose Symbolic
Instruction Code
Objects ready
to use!!
9
10
You perform
executing VBA code.
actions
in
VBA
by
VBE
12
A procedure is basically
a unit of computer code that performs
some action. VBA supports two types
of procedures: Sub procedures and
Function procedures.
Sub: A Sub procedure consists of a
series of statements and can be
executed in a number of ways.
Sub Test()
Sum = 1 + 1
MsgBox "The answer is " & Sum
End Sub
13
Objects
.VBA manipulates objects contained in
its host application. (In this case,
access is the host application.)
.Access provides you with more than
100 classes of objects to manipulate.
1.
15
of objects in Access:
16
2.
17
3.
18
1.
Forms!myForm!TextBox.Value
19
Sub ChangeValue()
Forms!myForm!TextBox.Value = 123
End Sub
2.
21
VBE Menu
Bar
VBE
Toolbars
Project
Explore
r
Window
Code
Window
Sub: a
Declaring
Sub Procedure
(Required)
The keyword that
Sub
name
([arglist])
[instructions]
[instructions]
End Sub
name:
(Required)
Any
valid
procedure name.
arglist: (Optional) Represents a list
of
variables,
enclosed
in
parentheses,
that
receive
arguments
passed
to
the
procedure.
instructions: (Optional) Represents
valid VBA instructions.
End Sub: (Required) Indicates the
end of the procedure.
23
24
1.
2.
Exercise 2
Create
27
References
Excel
28