562 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Commenting out code in VBA
Part two of a three-part series of blogs
Commenting code is an art form! This series of blogs explains why, how and when to comment in VBA.
This online training blog shows how to add comments to VBA (Visual Basic for Applications) code. The ideas shown work in Access, Word, PowerPoint and all other MS Office applications, but the diagrams come from Excel Visual Basic.
An example of commented code in Visual Basic for Excel
Any comment in VBA begins with a single apostrophe character ('). When you type in a comment and press the Enter key, the line will go green. For comments spanning multiple lines, you'll need to type the ' key multiple times:
This comment runs for 2 lines
Note that there is one other way to get multiline comments, and that's to use an _ underscore continuation character after all but the first lines:
It seems easier to this owl just to use repeated apostrophes!
Note that comments don't have to start at the beginning of lines:
Anything after the apostrophe in each line will be ignored by VBA
If you don't like the colour green - change it! The first thing to do is to go into the VBA editor's options:
First, go into the VBA code editor's options dialog box as shown on the left.
Now choose to change the colour for your comments as follows:
To change the comment colour:
You can also comment out code, as described in the next blog in this series.
|Parts of this blog|
25 Aytoun Street