Page 53 - Excel for Scientists and Engineers: Numerical Methods
P. 53

30                                         EXCEL: NUMERICAL METHODS



               a specific worksheet by  using either Worksheets("Book1") or Worksheets(3).
               The latter form is useful, for example, if you want to examine all the worksheets
               in a workbook, without having to know what text is on each sheet tab.
                   There  is  a  hierarchy  of  objects.   A  Range object  is  contained  within  a
               Worksheet object, which  is contained within a Workbook object. You  specify
               an  object  by  specifying  its  location  in  a  hierarchy,  separated by  periods,  for
               example,
                      Workbooks("Book1 ").Worksheets("Sheet3").Range("E5")

                   In the above example, if you don't specify a workbook, but just use
                      Works heets("S hee t3"). Range( "E5")
               you are referring to the active workbook.  If you don't specify either workbook or
               worksheet, e.g.,
                      Range("E5")
               you are referring to cell E5 in the active sheet.
                   Instead of the  keyword Worksheets, you  may  sometimes need to use the
               keyword Sheets.  Sheets is the collection that includes all sheets in a workbook,
               both worksheets and chart sheets.
                   A  complete list  of objects  in  Microsoft Excel  is  listed in  Excel's  On-line
               Help.  You can also use the Object Browser to see the complete list of objects.
               To display the  Object  Browser dialog box, choose Object Browser from the
               View menu in the VBE.

               "Objects" That Are Really Properties
                   Although Activecell and Selection are properties, not objects, you can treat
               them  like objects.  (Activecell  is  a property  of the Application object,  or the
               Activewindow property of the Application object.)  The Application object has
               the following properties that you can treat just as though they were objects: the
               Activewindow,  ActiveWorkbook,  Activesheet,  Activecell,  Selection  and
               Thisworkbook properties.  Since there is only one Application object, you can
               omit the reference to Application and simply use Activecell.

               You Can Define Your Own Objects
                   The Set keyword lets you define a variable as an object, so that you can use
               the variable name in your code, rather than the expression for the object.  Most
               often  this  is  done  simply  for  convenience; it's  easier  to  type  or  remember  a
               variable  name  rather  than  the  (perhaps)  long  expression for  the  object.  The
               variable will have all of the properties of the object type.
   48   49   50   51   52   53   54   55   56   57   58