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

Specifying Chart Sizes

If you need a number of charts in your workbook to all be the same size, it can be a bother to manually change each of ...

Discover More

Appending to a Non-Excel Text File

Does your macro need to add information to the end of a text file? This is called appending, and is done using the ...

Discover More

Setting a Default for Shifting when Inserting

When you insert cells into a worksheet, Excel needs to know which direction it should shift the displaced cells. If you ...

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)

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

Adding Comments to Your Document

If you would like to add non-printing notes to your document, the Comments feature is one way of doing that. Here's how ...

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 6 - 0?

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.