Excel Object VBA Overview
- 04:41
How Excel VBA is arranged into a hierarchy of objects and an introduction to their properties and methods
Downloads
No associated resources to download.
Glossary
Excel Object VBA OverviewTranscript
Excel.
Like other Microsoft Office applications is arranged into objects and collections of objects.
Each object, whether it's a chart, a worksheet, or even a single cell, has a predefined set of properties and another set of attributes called methods.
We'll explore Excel VBAs objects and understand how to manipulate those objects.
Using VBA programming language, the objects in Excel sit in a hierarchy with the application sitting at the top of the hierarchy.
When referring to an object in Excel VBA, we need to use its address.
If we're referring to the Excel application, we can use the word application.
If we want to refer to a cell in a worksheet, we can use its full address.
Looking at the example, we start off with application.
This is the application object.
Part of the application is the Work Books collection of object.
The work books collection of objects sits within the application of object and we split the application and the workbooks collection with a full stop or a period.
Within the workbooks collection.
There is a workbook called Book 2, full Stop or Period.
And within workbook two we have a set of worksheets.
The worksheet collection sits within the workbook called Book 2, and within that collection of worksheet objects there is a worksheet named sheet full stop or period again.
And finally within the worksheet there is a range object.
In the example. This is Range A1 Collections are groups of objects of the same class and can be coded in the same way as objects.
However, if we are currently in the Excel application in a file named Book 2 and in a worksheet named sheet, then we can cut this address right down and just refer to the cell using range A1.
Notice this is slightly different to how we refer to a cell in the front end of Excel.
In VBA, we need to put speech marks around our cell reference.
In Excel VBA, each object and collection of objects has a set of properties.
Think of these as characteristics of The object.
For example, cell has the value property.
Each object also has a set of methods.
Think of these as actions.
If a method is performed, we are telling the object to do something or taking action such as copying, for example.
It can be difficult to know all the properties and methods that relate to an object and also what the required arguments are When writing the code for a certain method.
Excel VBA has two useful help features that will make our lives easier.
Auto list members in Excel VBA from the Ribbon Select tools.
Then options edit a tab and check the auto list members checkbox.
This option provides a list of methods and properties that are available for the Object Auto List. Members will enable an automatic list of relevant properties and methods as you type in the VBA editor window auto Quick info in Excel VBA from the Ribbon Select tools.
Then options in the editor tab, check the auto quick info checkbox auto quick info specifies the arguments required by a property or method.
Checking. This option will mean we are presented with the arguments required as we are typing in the VBA editor window.