Rem Statement

Syntax

Rem comment
' comment

comment

Use: Optional

A textual comment to place within the code.

Description

Use the Rem statement or an apostrophe (') to place remarks within the code.

Rules at a Glance

  • Text or code commented out using either the Rem statement or an apostrophe isn't compiled into the final program and therefore doesn't add to the size of the executable.

  • If you use the Rem statement on the same line as program code, a colon is required after the program code and before the Rem statement. For example:

    Set objDoc = MyApp.MyObj : Rem Define the object
                               Rem reference

    This isn't necessary when using the now more common apostrophe:

    Set objDoc = MyApp.MyObj   ' Define the object reference
  • Apostrophes held within quotation marks aren't treated as comment markers, as this code snippet shows:

    myVar = "'Something'"

Programming Tips and Gotchas

  • The VB and VBA development environments contain block comment and block uncomment buttons on the Edit toolbar, which allow you to comment out or uncomment a selection of many rows of code at once.

  • You can also use the line continuation character ( _ ) with comments, as this snippet shows:

    'this is _
    a comment _
    on more than one line

Get VB & VBA in a Nutshell: The Language now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.