Review related procedures in class Document (Word VBA)

This page presents procedures from class Document related to the theme Review: AcceptAllRevisions, AcceptAllRevisionsShown, CheckConsistency, CheckGrammar, CheckSpelling, Comments, Compare, DeleteAllComments, DeleteAllCommentsShown, EndReview, Final, GrammarChecked, GrammaticalErrors, RejectAllRevisions, RejectAllRevisionsShown, Revisions, SendForReview, ShowGrammaticalErrors, ShowSpellingErrors, SpellingChecked, SpellingErrors and TrackRevisions

AcceptAllRevisions

Accepts all tracked changes in the specified document.

If ActiveDocument.Revisions.Count >= 1 Then _ 
 ActiveDocument.AcceptAllRevisions

AcceptAllRevisionsShown

Accepts all revisions in the specified document that are displayed on the screen.

Use the RejectAllRevisionsShown method to reject all revisions in a specified document that are displayed on the screen.

Sub AcceptAllChanges() 
 Dim rev As Reviewer 
 With ActiveWindow.View 
 'Display all comments and revisions 
 .ShowRevisionsAndComments = True 
 .ShowFormatChanges = True 
 .ShowInsertionsAndDeletions = True 
 
 For Each rev In .Reviewers 
 rev.Visible = True 
 Next 
 
 'Hide only the revisions/comments made by the 
 'reviewer named "Jeff Smith" 
 .Reviewers(Index:="Jeff Smith").Visible = False 
 End With 
 
 'Accept all revisions displayed in the active view 
 ActiveDocument.AcceptAllRevisionsShown 
 
End Sub

CheckConsistency

Searches all text in a Japanese language document and displays instances where character usage is inconsistent for the same words.

ActiveDocument.CheckConsistency

CheckGrammar

Begins a spelling and grammar check for the specified document or range.

If the document or range contains errors, this method displays the Spelling and Grammar dialog box, with the Check grammar check box selected. When applied to a document, this method checks all available stories (such as headers, footers, and text boxes).

ActiveDocument.CheckGrammar

CheckSpelling

Begins a spelling check for the specified document or range.

If the document or range contains errors, this method displays the Spelling and Grammar dialog box (Tools menu), with the Check grammar check box cleared. For a document, this method checks all available stories (such as headers, footers, and text boxes).

Syntax : expression.CheckSpelling (CustomDictionary, IgnoreUppercase, AlwaysSuggest, CustomDictionary2, CustomDictionary3, CustomDictionary4, CustomDictionary5, CustomDictionary6, CustomDictionary7, CustomDictionary8, CustomDictionary9, CustomDictionary10)

ActiveDocument.CheckSpelling

Arguments

The following arguments are optional

CustomDictionary - String

IgnoreUppercase (Boolean) - True if capitalization is ignored. If this argument is omitted, the current value of the IgnoreUppercase property is used.

AlwaysSuggest (Boolean) - True for Microsoft Word to always suggest alternative spellings. If this argument is omitted, the current value of the SuggestSpellingCorrections property is used.

CustomDictionary2 - String

CustomDictionary3 - String

CustomDictionary4 - String

CustomDictionary5 - String

CustomDictionary6 - String

CustomDictionary7 - String

CustomDictionary8 - String

CustomDictionary9 - String

CustomDictionary10 - String

Comments

Returns a Comments collection that represents all the comments in the specified document.

For information about returning a single member of a collection, see Returning an object from a collection.

For Each comm In ActiveDocument.Comments 
 If comm.Author <> Application.UserName Then _ 
 comm.Reference.Font.ColorIndex = wdRed 
Next comm

Compare

Displays revision marks that indicate where the specified document differs from another document.

Syntax : expression.Compare (Name, AuthorName, CompareTarget, DetectFormatChanges, IgnoreAllComparisonWarnings, AddToRecentFiles, RemovePersonalInformation, RemoveDateAndTime)

Sub CompareDocument() 
 ActiveDocument.Compare Name:="C:\Draft\FirstRev.doc", _ 
 CompareTarget:=wdCompareTargetNew 
End Sub

Arguments

The following argument is required

Name (String) - The name of the document with which the specified document is compared.

The following arguments are optional

AuthorName (String) - The reviewer name associated with the differences generated by the comparison. If unspecified, the value defaults to the author name of the revised document or the string "Comparison" if no author information is present.

CompareTarget (WdCompareTarget) - The target document for the comparison. Can be any WdCompareTarget constant.

Possible Values are wdCompareTargetCurrent - Places comparison differences in the current document. Default, wdCompareTargetNew - Places comparison differences in a new document, wdCompareTargetSelected - Places comparison differences in the target document.

DetectFormatChanges (Boolean) - True (default) for the comparison to include detection of format changes.

IgnoreAllComparisonWarnings (Boolean) - True compares the documents without notifying a user of problems. The default value is False.

AddToRecentFiles (Boolean) - True adds the document to the list of recently used files on the File menu.

RemovePersonalInformation (Boolean) - True removes all user information from comments, revisions, and the properties dialog box in the returned Document object . The default value is False.

RemoveDateAndTime (Boolean) - True removes date and time stamp information from tracked changes in the returned Document object. The default value is False.

DeleteAllComments

Deletes all comments from the Comments collection in a document.

Use the Add method for the Comments object to add a comment to a document.

Sub DelAllComments() 
 ActiveDocument.DeleteAllComments 
End Sub

DeleteAllCommentsShown

Deletes all revisions in a specified document that are displayed on the screen.

Sub HideDeleteComments() 
 Dim rev As Reviewer 
 With ActiveWindow.View 
 'Display all comments and revisions 
 .ShowRevisionsAndComments = True 
 .ShowFormatChanges = True 
 .ShowInsertionsAndDeletions = True 
 
 For Each rev In .Reviewers 
 rev.Visible = True 
 Next 
 
 'Hide only the revisions/comments made by the 
 'reviewer named "Jeff Smith" 
 .Reviewers(Index:="Jeff Smith").Visible = False 
 End With 
 
 'Delete all comments displayed in the active view 
 ActiveDocument.DeleteAllCommentsShown 
End Sub

EndReview

Terminates a review of a file that has been sent for review using the SendForReview method or that has been automatically placed in a review cycle by sending a document to another user in an email message.

When executed, the EndReview method displays a message asking the user whether to end the review.

Sub EndDocRev() 
 ActiveDocument.EndReview 
End Sub

Final

Returns or sets a Boolean that indicates whether a document is final.

True marks the document as final, notifies recipients (if any) that the document is final, and sets the document to read-only.

ActiveDocument.Final = True

GrammarChecked

True if a grammar check has been run on the specified range or document.

Returns False if all or some of the specified document has not been checked for grammar. To recheck the grammar in a document, set the GrammarChecked property to False.

Set myStat = ActiveDocument.ReadabilityStatistics 
passGram = ActiveDocument.GrammarChecked 
If passGram = True Then 
 Msgbox myStat(1).Name & " - " & myStat(1).Value 
Else 
 ActiveDocument.CheckGrammar 
End If

GrammaticalErrors

Returns a ProofreadingErrors collection that represents the sentences that failed the grammar check in the specified document.

There can be more than one error per sentence. If there are no grammatical errors, the Count property for the ProofreadingErrors collection returned by the GrammaticalErrors property returns 0 (zero). For information about returning a single member of a collection, see Returning an object from a collection.

If ActiveDocument.GrammaticalErrors.Count = 0 Then 
 Msgbox "There are no grammatical errors." 
Else 
 ActiveDocument.CheckGrammar 
End If

RejectAllRevisions

Rejects all tracked changes in the specified document.

If ActiveDocument.Revisions.Count >= 1 Then _ 
 ActiveDocument.RejectAllRevisions

RejectAllRevisionsShown

Rejects all revisions in a document that are displayed on the screen.

Sub RejectAllChanges() 
 Dim rev As Reviewer 
 With ActiveWindow.View 
 'Show all revisions in the document 
 .ShowRevisionsAndComments = True 
 .ShowFormatChanges = True 
 .ShowInsertionsAndDeletions = True 
 
 For Each rev In .Reviewers 
 rev.Visible = True 
 Next 
 
 'Hide revisions made by "Jeff Smith" 
 .Reviewers(Index:="Jeff Smith").Visible = False 
 End With 
 
 'Reject all revisions displayed in the active view 
 ActiveDocument.RejectAllRevisionsShown 
End Sub

Revisions

Returns a Revisions collection that represents the tracked changes in the document or range.

For information about returning a single member of a collection, see Returning an object from a collection.

MsgBox ActiveDocument.Sections(1).Range.Revisions.Count

SendForReview

Sends a document in an email message for review by the specified recipients.

The SendForReview method starts a collaborative review cycle. Use the EndReview method to end a review cycle.

Syntax : expression.SendForReview (Recipients, Subject, ShowMessage, IncludeAttachment)

Sub WebReview() 
 ActiveDocument.SendForReview _ 
 Recipients:="[email protected]; amy jones", _ 
 Subject:="Please review this document.", _ 
 ShowMessage:=False, _ 
 IncludeAttachment:=True 
End Sub

Arguments

The following arguments are optional

Recipients (String) - A string that lists the people to whom to send the message. These can be unresolved names and aliases in an email phone book or full email addresses. Separate multiple recipients with a semicolon (;). If left blank and ShowMessage is False, you will receive an error message and the message will not be sent.

Subject (String) - A string for the subject of the message. If left blank, the subject will be: Please review "file name".

ShowMessage (Boolean) - A Boolean value that indicates whether the message should be displayed when the method is executed. The default value is True. If set to False, the message is automatically sent to the recipients without first showing the message to the sender.

IncludeAttachment (Boolean) - A Boolean value that indicates whether the message should include an attachment or a link to a server location. The default value is True. If set to False, the document must be stored at a shared location.

ShowGrammaticalErrors

True if grammatical errors are marked by a wavy green line in the specified document.

To view grammatical errors in your document, you must set the CheckGrammarAsYouType property to True.

Options.CheckGrammarAsYouType = True 
ActiveDocument.ShowGrammaticalErrors = True

ShowSpellingErrors

True if Microsoft Word underlines spelling errors in the document.

To view spelling errors in a document, you must set the CheckSpellingAsYouType property to True.

ActiveDocument.ShowSpellingErrors = False

SpellingChecked

True if spelling has been checked throughout the specified range or document. False if all or some of the range or document has not been checked for spelling.

To recheck the spelling in a range or document, set the SpellingChecked property to False. To see whether the range or document contains spelling errors, use the SpellingErrors property.

Documents("MyDocument.doc").SpellingChecked = False 
Documents("MyDocument.doc").CheckSpelling IgnoreUppercase:=False

SpellingErrors

Returns a ProofreadingErrors collection that represents the words identified as spelling errors in the specified document or range.

For information about returning a single member of a collection, see Returning an object from a collection.

myErr = ActiveDocument.SpellingErrors.Count 
If myErr = 0 Then 
 Msgbox "No spelling errors found." 
Else 
 Msgbox myErr & " spelling errors found." 
End If

TrackRevisions

True if changes are tracked in the specified document.

With ActiveDocument 
 .TrackRevisions = True 
 .ShowRevisions = True 
End With