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

Automating Copying Macros

You can manually copy macros from one workbook to another, but what if you want to automate the copying process? Here's ...

Discover More

Embedding Fonts in a Document

Fonts are essential to getting your text to look just the way you want it to look. If you have a font that you use in a ...

Discover More

Automatically Copying Formatting

It's easy to automatically set the contents of one cell to be equal to another cell. But what if you want to copy the ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Deleting All Comments

Have comments in your document? Want to get rid of them all? The easiest way to do so is going to depend on the ...

Discover More

Converting Text to Comments

One of the strong suits of macros is that they can process the information in a document quickly and reliably. For ...

Discover More

Printing Comments

Comments are a great way to share, well, comments with other people looking through your documents. If you want to print ...

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 one less than 9?

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.