Visual Basic For Applications Lesson Nine: Vba Objects and Properties
Visual Basic For Applications Lesson Nine: Vba Objects and Properties
An Object represents an element [part] of an application, such as a cell, a form, a bookmark or a button. In Visual
Basic code, you must identify an object before you can reference [refer to] one of its properties.
You have already used Objects and Properties in these lessons .
In Lesson Three
OptionButtton2.value = False
Etc.
Here you set the Value property of the object OptionButton2 to False.
In Lesson Eight:
If Err.Number = 13 Then
Etc.
Here you asked if the Number property of the object Err was 13.
SO
The property of an object can either be set [given a value], or referenced. [Its value asked or used]
You will find that in the VB Editor, when you type the name of an object, then type a . directly after it,
indicating you wish to reference it [refer to it], you will be prompted with a list of valid properties. Try it now.
Create a Command button, then enter the VBA Editor.
Copy in the following script.
Dim Message
Message = Err.Number
MsgBox(Message)
The result should be 0, because there is no error.
Try some of the following remembering to reference them fully by replacing the ? with a property.
Message =ActiveDocument.Hyperlinks.? OR
Message =ActiveDocument.Bookmarks.? OR
To see a listing of ALL Objects and their properties, open View Object Browser in the VB Editor.
Look more closely at Lessons 3 and 8 as mentioned above to see how referencing Objects and their Properties is an
essential part of using VBA.
Sub CreateRecord()
Dim MyRecord As EmployeeRecord
MyRecord.ID = 12003
End Sub