Locked lesson.
About this lesson
Looking at the different keywords and structure that make up a valid macro.
Exercise files
There are no related exercise files for this lesson.
Quick reference
Understanding Code: Macro Syntax
An overview of VBA subroutine syntax.
When to use
To understand the key portions of a subroutine signature and how to read it (so that you can evenutally write your own.)
Key Components of SubRoutine Signature
Example
[Scope] Sub Name([Parameter1],[…])
‘Code goes here
End Sub
Observations
- [Scope] is optional, and will default to "Public" if left blank.
- Sub is short for “subroutine” and always appears at the beginning.
- Name is the name of the macro subroutine.
- The open and close parentheses () are always required
- [Parameters] within the parentheses are optional, and may or may not be present.
- A subroutine always ends with End Sub.
Hints & tips
- Optional items appear in square brackets
- Anything after a single quote (‘) are comments and are not executed at run time
Lesson notes are only available for subscribers.