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:
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.
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!
When developing a document, a common practice is to use comments to discuss changes with other people or to make notes ...
Discover MoreWord provides quite a bit of flexibility in what markup is displayed on-screen and how that markup appears. This tip ...
Discover MoreNeed 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 MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments