Aracılığıyla paylaş


How to: Check Spelling in Documents

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Word 2003

  • Word 2007

For more information, see Features Available by Application and Project Type.

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

To check spelling and display results in a message box

  • Call the CheckSpelling(String, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object) 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,
        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
    
    if (spellCheck == true)
    {
        result = "Spelled correctly.";
    }
    
    MessageBox.Show(result);
    

See Also

Tasks

How to: Define and Select Ranges in Documents

Concepts

The Variable missing and Optional Parameters in Office Solutions