Jaa


How to: Programmatically check spelling in documents

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

To check the spelling in a document, use the CheckSpelling method. This method returns a Boolean value that indicates whether the supplied parameter is spelled correctly.

Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Word. For more information, see Features available by Office application and project type.

To check spelling and display results in a message box

  1. Call the CheckSpelling method and pass it a range of text to check for spelling errors. To use this code example, run it from the ThisDocument or ThisAddIn class in your project.

    Dim result As String = "Spelled incorrectly."
    
    If Me.Application.CheckSpelling(Me.Range.Text) = True Then
        result = "Spelled correctly."
    End If
    
    MessageBox.Show(result)
    
    string result = "Spelled incorrectly.";
    
    object startLocation = this.Content.Start;
    object endLocation = this.Content.End;
    bool spellCheck = this.Application.CheckSpelling(
        this.Range(ref startLocation, ref endLocation).Text);
    
    if (spellCheck == true)
    {
        result = "Spelled correctly.";
    }
    
    MessageBox.Show(result);
    

See also