Word Hacks [Electronic resources]

Andrew Savikas

نسخه متنی -صفحه : 162/ 61
نمايش فراداده

Hack 36 Delete All Comments in a Document

Word 2002 and 2003 include a command on the Reviewing toolbar that deletes all the comments in a document. For users of earlier versions of Word, this hack does the same thing.

Comments let one or more reviewers comment on the text of a document without interfering with the content of the document. But once you finish editing or reviewing a document, getting rid of those comments can be a hassle.

To quickly delete a single comment, right-click its reference and choose Delete Comment from the shortcut menu [Hack #3]. But if you're facing dozens or hundreds of comments, deleting each one in turn will take you quite a while.

Another method for deleting comments is to use Find and Replace. Select EditReplace and do the following:

Leave the Find What box empty.

Click the Format button, choose Style, and select the Comment Reference style. (Don't see the Format button? Click the More button to make it visible.)

Leave the Replace With box empty.

Click the Replace All button.

But occasionally some comments just won't go quietly, so a VBA macro is your best bet for quickly getting rid of them.

4.11.1 The Code

Place this macro in the template of your choice [Hack #50] and either run it from the ToolsMacroMacros dialog or put a button for it on a menu or toolbar [Hack #1] :

Sub DeleteAllComments
Dim i As Integer
For i = ActiveDocument.Comments.Count To 1 Step -1
ActiveDocument.Comments(i).Delete
Next i
End Sub

If you're concerned about running the macro unintentionally, perhaps because you've placed it on a toolbar near another command you use frequently, the following version includes a prompt asking you to confirm that you do indeed want all the comments deleted, as shown in Figure 4-19. It also pops up a message when it finishes, notifying you how many comments were removed.

Sub DeleteAllCommentsAndConfirm( )
Dim i As Integer
Dim iNumberOfComments As Integer
If MsgBox( _
"Are you sure you want to delete ALL comments in this document?", _
vbYesNo) = vbYes Then
iNumberOfComments = ActiveDocument.Comments.Count
For i = iNumberOfComments To 1 Step -1
ActiveDocument.Comments(i).Delete
Next i
MsgBox iNumberOfComments & " Comment(s) Deleted", vbInformation
End If
End Sub

Figure 4-19. Confirming that you want to delete all comments in a document