Partager via


DocumentBase.GrammaticalErrors Property

Gets a ProofreadingErrors collection that represents the sentences that failed the grammar check on the document.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Syntax

'Declaration
Public ReadOnly Property GrammaticalErrors As ProofreadingErrors
public ProofreadingErrors GrammaticalErrors { get; }

Property Value

Type: Microsoft.Office.Interop.Word.ProofreadingErrors
A ProofreadingErrors collection that represents the sentences that failed the grammar check on the document.

Remarks

There can be more than one error per sentence.

If there are no grammatical errors, the Count property for the ProofreadingErrors object returned by the GrammaticalErrors property returns 0 (zero).

Examples

The following code example adds ungrammatical text to the first paragraph and then checks whether there are any errors. To use this example, run it from the ThisDocument class in a document-level project.

Private Sub DocumentGrammaticalErrors()
    Me.Paragraphs(1).Range.InsertParagraphAfter()
    Me.Paragraphs(1).Range.Text = "This is a ungrammatical sentence." 
    Me.CheckGrammar()
    System.Windows.Forms.Application.DoEvents()
    If Me.GrammaticalErrors.Count = 0 Then
        MessageBox.Show("There are no grammatical errors.")
    Else 
        Me.CheckGrammar()
    End If 
End Sub
private void DocumentGrammaticalErrors()
{
    this.Paragraphs[1].Range.InsertParagraphAfter();
    this.Paragraphs[1].Range.Text = "This is a ungrammatical sentence.";
    this.CheckGrammar();
    System.Windows.Forms.Application.DoEvents();
    if (this.GrammaticalErrors.Count == 0 )
    {
        MessageBox.Show("There are no grammatical errors.");
    }
    else
    {
        this.CheckGrammar();
    }
}

.NET Framework Security

See Also

Reference

DocumentBase Class

Microsoft.Office.Tools.Word Namespace