Creating a Procedure
There are two ways to create a new procedure (subroutine or function) within a code module. First, after selecting the correct project in the Project Explorer, we can select the Procedure option from the Insert menu. This will produce the dialog box shown in Figure 4-1. Just type the name of the procedure and select Sub or Function. (The Property choice is used with custom objects in a class module.) I discuss the issue of public versus private procedures and static variables later in this chapter.

Figure 4-1. The Add Procedure dialog box
A simpler alternative is to simply begin typing:
Sub SubNameor:
Function FunctionNamein any code window (following the current EndSub or EndFunction statement) or in the General window. As soon as you press the Enter key, Word will move the line of code to a new location and thereby create a new subroutine. (It will even add the appropriate ending—End Sub or End Function.)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access