You can either type a Sub procedure directly into the Modules window, or the Visual Basic Editor can insert it for you. Sub procedures all begin with the line: Sub ProcedureName( ) where ProcedureName is the name of the Sub procedure. If the Sub procedure includes arguments, enter them between the opening and closing parentheses. Not every Sub procedure requires arguments. After entering the first line, which names the procedure, you can insert the procedure's VBA commands. Each Sub procedure ends with the line: End Sub
Create a Sub Procedure
- In the Visual Basic Editor, click the Module window to select it.
- Click the Insert menu, and then click Procedure.
- Enter the procedure's name.
- Click the Sub option, if necessary.
- Click OK.The Editor inserts the opening and closing lines of the new Sub procedure.