Microsoft Office Tutorials and References
In Depth Information
To add a new procedure to a module or class module, you can type directly into the code win­
dow of the module. You can also click Insert, Procedure to open the Add Procedure dialog
box, shown in Figure 4-8, which will prompt you for the minimum information needed to
create a procedure.
Figure 4-8. The Add Procedure dialog box lets you determine the basic outline of
your procedure.
Note You can find more information on the options available in the Add Procedure dialog
box later in this chapter.
Notes on Programming Style and Code Readability
Programmers come from many different backgrounds, and each has their own style of writ­
ing code. Programmers who work for or have worked for large software companies might
follow a strict format specified by the company, while solo programmers might follow no set
format. While neither the company nor the solo programmer is necessarily right or wrong, it
is absolutely vital that you write code that is easy to read and understand. Even if you
understand the code you write today, you or another programmer might need to modify it in the
future. Unless you have a photographic memory, you might have difficulties understanding
the logic you wrote earlier and find it that much harder to make your changes.
There are several steps you can take to make your code as readable as possible.
Keep your procedures as short as possible. If you need a macro that will open a
workbook, ask the user for information, make changes to the workbook, then save and close
the workbook, and then break the macro up into several procedures: one procedure for
each task. Then have one main procedure to call the other procedures. This format of
constructing a series of subprocedures that are called by a main procedure will also
make finding and correcting programming errors (debugging) easier because you will
be able to narrow it down to a much smaller section of code.
Search JabSto ::




Custom Search