DocumentBase.GrammaticalErrors Property

Definition

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

public:
 property Microsoft::Office::Interop::Word::ProofreadingErrors ^ GrammaticalErrors { Microsoft::Office::Interop::Word::ProofreadingErrors ^ get(); };
public Microsoft.Office.Interop.Word.ProofreadingErrors GrammaticalErrors { get; }
member this.GrammaticalErrors : Microsoft.Office.Interop.Word.ProofreadingErrors
Public ReadOnly Property GrammaticalErrors As ProofreadingErrors

Property Value

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

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 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();
    }
}
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

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).

Applies to