An Inline Commenting Macro

Inline comments—that is, comments inserted within the body of a document—can be a very useful alternative to Word’s built-in Comments tool (in a previous post I discuss their pros and cons). However, formatting them so that they stand out from the text requires a few extra keystrokes for each comment.

To make formatting less labor intensive, I cooked up a short macro (presented below) that automates the process. Its operation is very simple. If the user types a comment, selects it, and runs the macro, the comment will be reformatted: braces will be placed on either end of the comment, and the braces and comment will have the built-in Word style Strong applied to them. If the macro is run without any text being selected, a set of braces will be inserted, the Strong style will be applied to them, and the cursor placed between the braces, allowing a comment to be easily entered. For the macro to really save you work, you will need to assign it a keyboard shortcut (I use Ctrl+Alt+q).

Using a Word style allows all comments to be quickly reformatted by changing the definition of the style. It also allows all comments to be quickly selected using the Select All option in the Styles toolbar; this can be handy if you want to quickly delete or copy all comments. The macro’s use of the predefined Strong style can be a problem if you are using that style for other content in your document, but this can be fixed by changing the name of the style referenced in the macro. Since the macro applies one style to all comments, color-coding isn’t supported. However, if you prefer to color-code comments, one option is to replace the line in the macro stating

Selection.Range.Style = wdStyleStrong

with

Selection.Range.HighlightColorIndex = Options.DefaultHighlightColorIndex

to apply the current highlighting color, rather than a text style, to each inline comment as it is created.

Note: While poking around on the internet recently, I came across a similar but more elaborate set of macros, created by Professor Benjamin L. Read, for working with inline notes. If you are interested in color-coding your notes, his macros might be useful to try out.

 


The Code

Sub InsertInlineComment()
'Written by Michael Schuler, 2014.
'Recommended shortcut: CTRL+ALT+q
    Set myRange = Selection
    myRange.InsertBefore " {"
    myRange.InsertAfter "} "
    Selection.Range.Style = wdStyleStrong
    Selection.MoveLeft Count:=1
    Selection.MoveRight Count:=2
End Sub

 

Submit a Comment

Your email address will not be published. Required fields are marked *