Acting Directly on Objects in Visual Basic

In Microsoft Excel version 4.0, macros follow the "select, then do" order of actions that pertains to all of Microsoft Excel. With Visual Basic, you don't need to select an object you want your procedure to change. You can change the object directly.

For example, to make a range of text bold in Microsoft Excel version 4.0, you have to first select the range with the SELECT function before changing the format of the text with the FORMAT.FONT function. In Visual Basic, you make a range of text bold just by setting the Bold property of the range to True. For example, type the following function in a module:


Sub MakeSectionBold()
    Worksheets("Sheet1").Range("C1:G5").Font.Bold = True
End sub

Note that you can use Visual Basic to directly change an object (in this case, the range C1:G5) without selecting it or canceling the current selection. For more information about how to change cells, sheets, charts, shapes, and other objects in Visual Basic, see Chapter 4, "Objects and Collections."