11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

606<br />

Part VI: Developing Custom Worksheet Functions<br />

A project may have another node called References. This node contains a list of all<br />

references that the project uses. You can add or remove References by choosing<br />

Tools➜References. Unlike other items listed in the Project window, Reference items<br />

don’t have an associated code module.<br />

Renaming a project<br />

By default, all projects are named VBAProject. In the Project window, the workbook name<br />

appears (in parentheses) next to the project name. For example, a project may appear as follows:<br />

VBAProject (budget.xlsm)<br />

You may prefer to change the name of your project to a more descriptive name. To do so, follow<br />

these steps:<br />

1. Select the project in the Project window.<br />

2. Make sure that the Properties window is displayed (press F4 if it’s not displayed).<br />

3. Use the Properties window to change the name from VBAProject to something else.<br />

After making the change, the Project window displays the new name.<br />

Adding a new VBA module<br />

A new Excel workbook does not have any VBA modules. To add a VBA module to a project,<br />

select the project’s name in the Project window and choose Insert➜Module.<br />

When you create custom worksheet functions, they must reside in a standard VBA<br />

module and not in a code window for a Sheet object (for example, Sheet1) or the<br />

ThisWorkbook object. If the code for your custom function does not reside in a VBA<br />

module, it won’t work. Putting VBA code in the wrong place is perhaps the most common<br />

error made by users who are learning to write custom worksheet functions.<br />

Renaming a module<br />

VBA modules have default names, such as Module1, Module2, and so on. To rename a VBA module,<br />

select it in the Project window, and then change the Name property by using the Properties<br />

window. (A VBA module has only one property — Name.) If the Properties window is not visible,<br />

press F4 to display it. Figure 22-8 shows a VBA module named Module1 that is being renamed to<br />

modFunctions.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!