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

Changing Sort Order

When sorting information, Word follows some pretty strict rules. If you want to modify how those rules are applied, you ...

Discover More

Special Characters in Pattern Matching

The most powerful search engine in Word use pattern matching, but the way you specify special characters in a ...

Discover More

Spellcheck for Two Languages

Are you creating a document that mixes different languages? Word can handle the multi-language scenario, but it may take ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Hiding Individual Comments

When developing a document, a common practice is to use comments to discuss changes with other people or to make notes ...

Discover More

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

Printing Comments from a Macro

Need to print the comments you've added to a document? You can do it manually or you can have your macro do the printing. ...

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 two more than 7?

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.