Deleting Commented Text

Written by Allen Wyatt (last updated September 12, 2020)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


Thomas has a large document that has items that should be removed before publishing the document for others. The parts of the document that need to be removed were selected and marked with a comment stating that it should be removed before publishing. Thomas would like to quickly find and replace all the text that was commented in this way and delete it. Using Find and Replace, all he can do is find the comments. He has not found a way to figure out if the comment is an indicator that the text should be deleted, nor has he figured out how to delete the actual document text that was highlighted.

This sounds like a rather involved task, as it involves many steps. You need to find a comment, you need to look at the body of the comment to see if it matches your desired wording, you need to delete the commented text in the document body, and then you need to delete the comment itself. This is a job for a macro.

Fortunately, all the comments in a document are accessible through the Comments group using VBA. You can step through each of the comments and see if it contains the "trigger text" to indicate the comment (and the text to which it refers) should be deleted. In the following example, if the comment text contains the words "delete this" anywhere within the comment, then this serves as the trigger.

Sub DeleteCommentsBaseText()
Dim c As Comment
For Each c In ActiveDocument.Comments
    If LCase(Trim(c.Range.Text)) Like "*delete this*" Then
        c.Scope.Delete
        c.DeleteRecursively
    End If
Next c
End Sub

If the trigger words are in the comment, then the Scope property is deleted; it is this property that indicates the document text that was selected when the comment was created. The DeleteRecursively method is then used to delete the actual comment. (The DeleteRecursively method was added in Word 2013. In earlier versions you should use the Delete method instead.)

Understand that when you run the macro it is very fast, and changes cannot be undone. If you want, instead, a bit more control over which comments and text are deleted, then you may want to rethink your workflow. If you use Track Changes, whoever places the comment could also mark the document text for deletion. Then, prior to finalizing the document, you can turn off Track Changes and step through each change to determine if it should be accepted or not. It is not nearly as fast as the above macro, but it gives you greater control.

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 (2490) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365.

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

Word Slow to Open Documents

If you've noticed a slowdown in Word when it is opening a document, you probably would like to speed up the operation. ...

Discover More

Trouble Recording Paste Special Formula

Sometimes, when you upgrade to a new version of Excel, you could run into a problem recording macros that you had no ...

Discover More

Using GEOMEAN with a Large List

When performing a statistical analysis on a large dataset, you may want to use GEOMEAN to figure out the geometric mean ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Displaying Highlights for Commented Text

Word provides quite a bit of flexibility in what markup is displayed on-screen and how that markup appears. This tip ...

Discover More

Viewing Comments

Adding comments to a document is a normal activity when writing and editing. Once comments have been added, you may ...

Discover More

Formatting Comments

Need to change the appearance of the text in your comments? It's easy to do using techniques you are already familiar with.

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 nine minus 5?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.