Page 135 - Microsoft Office Excel 2003 Programming Inside Out
P. 135

Part 3:  The Excel Object Mode
                                                     The Application Object

                             The following Application object properties are the most used:
                               ●  ActiveCell
                               ●  ActiveChart
                               ●  ActiveSheet
                               ●  ActiveWindow
                               ●  ActiveWorkbook
                               ●  RangeSelection
                               ●  Selection
                               ●  ScreenUpdating
                               ●  StatusBar
                               ●  ThisWorkbook

                             You can get information on every element of the Excel object model in the Visual Basic Editor help system
                             by typing object model in the Ask A Question box and viewing the Microsoft Excel Object Model help topic.

                             The short list of Application properties contains the most common objects that are used
                             within Excel. Most have been exposed directly by the Excel programming team so that an
                             explicit reference to the application object isn’t needed. These properties are described in the
                             following sections in alphabetical order.

                             ActiveCell Property

                             The ActiveCell property is exactly what its name implies: a reference to the currently active
                             cell on the active work sheet on the active workbook. When called, the ActiveCell property
                             returns a Range object that can be used to set the value or formula of the cell along with any
                             formatting changes you might want to make (font style, borders, format of numbers, and
                             so on).
                             The following example uses the CellBorder procedure to examine the value of a cell and
                             change the border around the cell if it has a value between 500 and 1000. The ApplyBorders
                             procedure loops through all of the specified data cells within the Y2001ByMonth.xls work-
                             book, shown in Figure 6-2, and then calls the CellBorder procedure for each cell.
                             Sub ApplyBorders()
                             Dim MyCell As Range
                                 For Each MyCell In _
                                    ActiveSheet.Range(D6:O36").Cells
                                    MyCell.Select
                                    If ActiveCell > 500 And ActiveCell < 1000 Then
                                      With ActiveCell.Borders
                                        .Weight = xlThick
                                        .Color = vbBlue
                                      End With                                                               Chapter 6
                                    End If
                                 Next MyCell
                             End Sub

                                                                                                       109
   130   131   132   133   134   135   136   137   138   139   140