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

Microsoft Office Excel 2003 Programming Inside Out

                    Creating a Function Procedure
                             You can create a Function procedure in an existing code module by opening the module in
                             the Visual Basic Editor by typing the following:

                             Function name()
                             …
                             End Function

                             You will need to name the function and put instructions in the middle where the ellipsis is
                             now, but you can do it much more quickly using the Add Procedure dialog box.
                             To add a Function procedure to a code module, follow these steps:

                               1  Click Tools, Macro, Visual Basic Editor to display the Visual Basic Editor.
                               2	 If necessary, click Insert, Module to create a new code module (or if you want to create
                                  a new module for organizational purposes).
                               3  Click Insert, Procedure to display the Add Procedure dialog box.
                               4  Type the name of your procedure in the Name box.
                               5  Select the Function option button.



















                               6  Click OK.

                             Note  As with Sub procedures, you can make your Function procedures available to pro
             Chapter 5
                             cedures in every other workbook by putting the Public keyword in front of the declaration.
                             The Public keyword is added by default when you add a procedure using the Insert Proce
                             dure dialog box.











                100
             Part 2:  Visual Basic for Applications
   121   122   123   124   125   126   127   128   129   130   131