Page 35 - Excel Progamming Weekend Crash Course
P. 35

d540629 ch01.qxd  9/2/03  9:27 AM  Page 10




                10                                                            Friday Evening

               components. Automation also permits components to interact with each other — for exam-
               ple, you could embed an Excel spreadsheet in a Word document. For the present purposes,
               automation permits a VBA program to use the Excel components. Other programming lan-
               guages, such as C++ or Java, can use automation too, but that is not relevant here.
                  The COM components that your VBA programs can use exist as files on your hard disk and
               were installed as part of the Office or Excel installation. A component can operate in two ways:
                   An automation client controls and makes use of classes exposed by other components.
                   An automation server exposes classes for use by other components.
                  An automation component can act in one or both of these roles. For programming Excel,
               VBA is acting as a client, and the Excel components are acting as servers. Some Excel com-
               ponents act as clients to manipulate other components.
                  The result of this arrangement is that an Excel programmer has VBA, a powerful program-
               ming language, as well as access to all of the components that comprise the Excel applica-
               tion. This is an extremely powerful combination — Excel is your well-trained and capable
               servant, and VBA is the means you use to tell it what to do. The sum of all the components
               exposed by Excel is referred to as the Excel object model.

                          The Excel object model is covered in detail later in the book, primarily in
                          Session 3.
                 Cross-Ref



               Macros and Programming
               If you have ever used Excel’s macro feature, you have already done some Excel program-
               ming. A macro is a sequence of user actions that is recorded and can be played back later to
               duplicate the original actions. This saves time because you don’t have to manually redo the
               steps each time. To record a macro, select Macro from Excel’s Tools menu and then select
               Record New Macro. As you perform actions in Excel, they are translated into the correspond-
               ing VBA commands. When you stop the recording, the resulting VBA is saved and can be
               played back as needed. Recording macros can be a useful tool for the Excel programmer.

                          Recording macros is covered in more detail in Session 2.

                 Cross-Ref


               Designing Your Custom Application

               When creating a custom Excel program, as with all programming, it is important to do some
               planning before you start writing code. The importance of planning cannot be overempha-
               sized. For a simple project it may take only a few minutes; for a large, complex project, it
               may take days. In either case it is going to save you time and hassles down the road.
                  Before you begin, make certain that you know what is needed. A lot of problems can
               arise when there is a misunderstanding between the client and the programmer. You may
   30   31   32   33   34   35   36   37   38   39   40