Text May Be Incorrectly Flagged as Misspelled When You Programmatically Check the Spelling and You Specify the Language Dictionary (832124)



The information in this article applies to:

  • Microsoft Word 2000

SYMPTOMS

When you run a Microsoft Visual Basic for Applications (VBA) macro that specifies the main dictionary to use to check the spelling of a word that is contained in a Microsoft Word document, text may be incorrectly flagged as misspelled.

CAUSE

This problem may occur if the Language ID (LID) is not applied to the text that is being checked.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

To work around this behavior, use the following VBA macro:
Function CheckSpellingWithLang(text As String, lid As WdLanguageID) As Boolean

   Dim oDoc As Document
   Set oDoc = Application.Documents.Add(Visible:=False)
   oDoc.Range.LanguageID = lid
   oDoc.Range.InsertAfter text

   If oDoc.SpellingErrors.Count > 0 Then
      CheckSpellingWithLang = False
   Else
      CheckSpellingWithLang = True
   End If

   oDoc.Close wdDoNotSaveChanges
   Set oDoc = Nothing

End Function

Sub test()

   Debug.Print CheckSpellingWithLang("dans", wdFrench)
   Debug.Print CheckSpellingWithLang("method", wdFrench)

End Sub

MORE INFORMATION

The problem that is described in the "Symptoms" section may occur if you run the following macro sample to find the French word "dans" ("dans" represents a French letter), and text is incorrectly flagged as misspelled.
Sub test()

   Dim sTestWord As String
   sTestWord = "dans"

   If Word.CheckSpelling(sTestWord, , , "French (France)") = True Then
      MsgBox "Word is found in the dictionary"
   Else
      MsgBox "Word is not found in the dictionary"
   End If

End Sub

Modification Type:MajorLast Reviewed:3/23/2006
Keywords:kbprb KB832124 kbAudEndUser kbAudDeveloper