Working with objects

As explained in the introductory article by MS, programming with VBA is all about working with objects. Objects are occurences (instances) of a class, with characteristic methods and properties, you can insert or activate a sheet, format a range of cells, and so on. Before you can start working with an object, in most cases you have to give the object a name, the variable, and specify which item you are refering to, the Set statement.

Working with objects from the menu

The image above shows the objects menu opened, corresponding to the code below. The menu has identified the two variables in the procedure, and knows which type they are and therefore which procedures are applicable. Additionally, it knows the built-in Me variable which is appropriate in case you are adding code to a class module. Finally, it knows of certain named objects: ThisWorkbook and Sheet1. THese can be worked with without first having to declare variables for them.

Selecting a variable or name opens a menu. The first procedures listed are those considered, somewhat arbitrarily, the most characteristic or most used for the class. If the procedure you are looking for is not listed there, click Methods or Properties to get access to all.

We tried to make the Object menu 'logical' and self-evident, a details discussion can be found here: Explaining the object menu

Sub Demo
Dim rngActiveCell As Range
Set rngActiveCell = ActiveCell
Dim wsActiveSheet As Worksheet
Set wsActiveSheet = ThisWorkbook.ActiveSheet