Objects

First up, this section covers a few basics about Object-Oriented Programming (OOP). This not a complete formal treatise on the subject, but it covers what you need to know to work with the objects in Excel.

OOP's basic premise is that you can describe everything known to us as objects. You and I are objects, the world is an object, and the universe is an object. In Excel, a workbook is an object, a worksheet is an object, and a range is an object. These objects are only a small sample of around two hundred object types available to us in Excel. Look at some examples of how to refer to Range objects in VBA code. One simple way to refer to cells B2:C4 is as follows:

Range("B2:C4")

If you give the name Data to a range of cells, you can use that name in a similar way:

Range("Data")

There are also ways to refer to the currently active cell and selection using shortcuts.

In Figure 1-17, ActiveCell refers to the B2 cell, and Selection refers to the range B2:E6. For more information on ActiveCell and Selection, see Chapter 3.

i Hn

A

- S3 i Recr'rdei.jitem

Microsott Deesl

¡11

g

-Irinn insErt Page LayouT Formulas

Date

Review

View DEveioper

S- - <*

T

B2

¥

4

B C D E

F

5

H I .

< m

1

1

3

1

4

5

S

7

8

9

10

MM '* 'H Bheetl 5heet2 Slieet3 3

m.----im —

j

m

■13

m

Figure 1-17

0 0

Post a comment