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

CHAPTER 2  FUNDAMENTALS .OLPROGRAMMING WITH VBA                       51



                How to Create an Add-In Macro
                   To save a workbook as an Add-In, choose Save As.. . from the File menu.
               Choose Microsoft Excel Add-In from the Save File As Type drop-down  list box,
               then  press  OK.  In  Excel  for  Windows,  Add-In  workbooks  are  automatically
                given the filename extension .xla.
                   When you save a workbook as an Add-In, the default location is the AddIns
                folder.
                   Command macros can also be saved as Add-Ins.


                Testing and Debugging

                   When  an  error  occurs  during  execution  of  a  procedure,  VBA  will  stop
                execution and display a run-time error message.  There are a large number (over
                50) of these run-time error messages.  Some (but not all) of these error messages
                are self-explanatory.  Here are some examples:
                Subscript out of range              Attempted  to  access  an  element  of  an
                                                    array outside its specified dimensions.
                Property or method not found        Object  does  not  have  the  specified
                                                    property or method.
                Argument not optional               A required argument was not provided.
                   The  line  of  code  in  which  the  error  occurred,  or  the  first  line  of  the
                procedure  (containing  the  Sub  or  Function  keyword)  will  be  highlighted,
                usually in  yellow (see Figure 2-22).  After you have corrected the error in your
                VBA code, the line will still be highlighted.  Press F5 to continue execution.
























                                Figure 2-22.  VBA code with a highlighted  line.
   69   70   71   72   73   74   75   76   77   78   79