Converting Text to Comments

Written by Allen Wyatt (last updated April 15, 2024)
This tip applies to Word 2007, 2010, 2013, and 2016


2

Moshe has a Word document that was edited by a copy editor. Anywhere that the editor inserted a comment, it starts with a left parenthesis, followed by "ed note:", then the note, and finally a right parenthesis. For Moshe's in-house processes, it is more advantageous to have these notes as actual Word comments. He wonders if there is a way to automate the finding of these in-text notes and covert them to Word comments.

The way to automate this process is through the use of a macro. The macro can rely on the Find and Replace capabilities of Word, but add some processing whenever a matching comment is located.

Sub NoteToComment()
    Dim sTemp As String

    Selection.HomeKey Unit:=wdStory

    With Selection.Find
        .ClearFormatting
        .Text = "\(ed note:*\)"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .MatchWildcards = True
    End With

    Do While Selection.Find.Execute
        sTemp = Selection.Text
        sTemp = Mid(sTemp, 10, Len(sTemp) - 11)
        sTemp = Trim(sTemp)
        Selection.Text = ""
        Selection.MoveEnd unit:=wdCharacter
        Selection.MoveStart unit:=wdCharacter, Count:=-1
        If Selection.Text = "  " Then Selection.Text = " "
        Selection.Collapse
        ActiveDocument.Comments.Add Range:=Selection.Range, Text:=sTemp
    Loop
End Sub

The macro first moves to the beginning of the document, then it sets up the conditions for searching. What is looked for is the pattern that Moshe noted—a left parenthesis, followed by "ed note:", then the note, and finally a right parenthesis—this sequence is assigned to the .Text property of the Find object. Note that each parenthesis has a backslash in front of it. If these backslashes weren't included, Word would consider the parentheses as control characters in the search pattern. In addition, the .MatchWildcards property is set to True so that the .Text property is treated as a search pattern.

In the Do While loop, which is entered each time a matching comment is found, the sTemp variable is set to the text of the comment. The first 9 characters are stripped off (these are "(ed note:") along with the final right parenthesis. The comment is removed from the document and if there are multiple spaces left after the removal, those are deleted as well. Finally, an actual comment is added that contains the text in the sTemp variable.

There is one thing to remember when using this macro: It is dependent on matching the comment pattern correctly. This means that if there are some comments that don't follow the pattern exactly, those may not be found and converted. (For instance, if there is a space after the opening left parenthesis.) Further, if the comments in the document contain parenthetical remarks within the comment (in other words, there are nested parentheses in the comment), that will mess up what is found by the wildcard search and what subsequently ends up in the comment.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1797) applies to Microsoft Word 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Automatically Using Smart Quotes

As a way to make your documents look more professional, Word can utilize "smart quotes" for both quote marks and ...

Discover More

Unwanted Styles

Want to get rid of some styles in a document that you don't need any more? It can be a difficult thing to do, unless you ...

Discover More

Using AutoComplete with Disjointed Lists

AutoComplete can help you to more quickly enter information in a worksheet. How it works, behind the scenes, can affect ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Jumping To a Comment

Got a document with lots of comments in it? You can navigate from comment to comment with ease by using the Go To tab of ...

Discover More

Default Font for Comments

Want your comments to stand out a bit more than normal or, to the contrary, to be minimized? You can affect how comments ...

Discover More

Getting Rid of "Comment" in Comments

When you add a comment to a document, Word presents that comment in a very specific way. If you want to change the way in ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 - 0?

2017-06-05 09:53:19

Andrew

I often need to do the reverse, especially when printing a document, much the way the original editor inserted his notes. So I use this macro:

Sub CommentsToInline()
Dim c As Comment
Dim rtext As Range ' referenced text
Dim trackingchanges As Boolean
Const SubName As String = "CommentsToInline"

If ActiveDocument.Comments.Count = 0 Then MsgBox "No comments in document.", vbExclamation, SubName: Exit Sub
If MsgBox("Convert " & ActiveDocument.Comments.Count & " comment(s)?", vbYesNo, SubName) <> vbYes Then Exit Sub
trackingchanges = ActiveDocument.TrackRevisions ' Retain state
ActiveDocument.TrackRevisions = False

For Each c In ActiveDocument.Comments
Set rtext = c.Scope
c.Range.Copy ' Using copy/paste to preserve formatting
With rtext
.Shading.BackgroundPatternColor = -704577741 ' Was too dark with .HighlightColorIndex = wdGray25
.Collapse wdCollapseEnd ' Collapse to end so can begin operating on the comment text
.Text = "{{" & c.author & ":" & "}}" ' Set up comment bracketing (with author) and its formatting
.Font.Color = wdColorBlue
.Font.Bold = True
.Font.Italic = False
.Font.Underline = wdUnderlineNone
.Collapse wdCollapseStart
.MoveStartUntil cset:="}" ' Move to before ending delimiter (just past the inserted colon)
.Paste
.Font.Bold = False
.Font.Italic = True
.Font.Name = "Arial"
.Font.Size = Round(0.8 * .Font.Size)
.Shading.BackgroundPatternColor = -704577741 ' Was too dark with .HighlightColorIndex = wdGray25
End With
c.Delete
Next c

ActiveDocument.TrackRevisions = trackingchanges ' Restore state
End Sub


2017-06-03 05:35:36

Harold Druss

The line below:
sTemp = Mid(sTemp, 10, Len(sTemp) - 11)
Should be:
sTemp = Mid(sTemp, 10, Len(sTemp) - 10)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.