Solved

VBA-Function checkSpelling() finds only words in default Language, but not in others

Posted on 2004-03-27
7
1,576 Views
Last Modified: 2012-05-04
Hi there!

Situation: I'd like to check the spelling of a single word in a VBA-code using different main dicitonaries each time. No dialog boxes for user inter-action should be used (therefore no call of checkSpelling-Method with a Range-Object).

Problem: Only the main dict of the default language is used even if another one is specified.
I use the German Word 2000 SP3 under Win2k or WinXP (also German).
I.e. the VBA-code does not recognize the french Word "roi" (king) in the German main dict (that's correct!) but also not in the French main dict:  
    sWord = "roi"
    found1 = CheckSpelling(sWord, , , "German")
    found2 = CheckSpelling(sWord, , , "French")
    MsgBox found1 & Chr$(10) & Chr$(13) & found2

Usage: Application.CheckSpelling(Word, CustomDictionary, IgnoreUppercase, MainDictionary, CustomDictionary2 – CustomDictionary10)
Info: the online-spellchecking in a document is working fine if the appropriate Language is specified!

Maybe it's due to compatibility reasons that the checkspelling-Function is not working properly

Thanks for the help!
Jan
0
Comment
Question by:yawnexp
7 Comments
 
LVL 17

Assisted Solution

by:Suat Ozgur
Suat Ozgur earned 30 total points
ID: 10694335
Hi Jan,

I have no chance to test it on different language dictionaries in word but MainDictionary parameter should be a dictionary object not a string like "German" or "French" (I think).

May be following might help.

    found1 = CheckSpelling(sWord, , , Languages(wdGerman).ActiveSpellingDictionary)
    found2 = CheckSpelling(sWord, , , Languages(wdFrench).ActiveSpellingDictionary)

Suat
0
 

Author Comment

by:yawnexp
ID: 10695329
Hi Suat,

I found the "French" argumented structure online as a result of a search engine inquiry.
I also thought of your solution before, but it's not working better:
    found1 = Application.CheckSpelling(sword, , , Languages(wdGerman).ActiveSpellingDictionary)
    found2 = Application.CheckSpelling(sword, , , Languages(wdFrench).ActiveSpellingDictionary)
Both function returns are always TRUE if I check a correct German (=standard language) word and FALSE if it's an incorrect German word or a foreign (i.e. French) word.  :-(

Any more ideas?
Jan

0
 
LVL 24

Assisted Solution

by:R_Rajesh
R_Rajesh earned 70 total points
ID: 10695887
Jan,
try using the namelocal property ("French France" for french, "German Germany" for German ...)

MsgBox Application.CheckSpelling("roi", MainDictionary:="French France")


to see what dictionaries are installed and available run this

Sub lnames()
For Each c In Languages
If Not c.ActiveSpellingDictionary Is Nothing Then b = b & c.NameLocal & vbLf
Next c
MsgBox b
End Sub

Rajesh
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10695904
well, i meant to post this one

MsgBox Application.CheckSpelling("roi", MainDictionary:=Languages(wdFrench).NameLocal)
0
 

Author Comment

by:yawnexp
ID: 10708562
I think we slightly circled the problem. I recognized an interesting system reaction:

No matter if I set
  MainDictionary:=Languages(wdFrench).NameLocal   or   MainDictionary:="Französisch (Frankreich)")   or
  MainDictionary:=Languages(wdFrench).Name   or   MainDictionary:="Français")
I get a runtime error message (4625): dictionary can’t be opened   (translated from German)

In contrast Languages(wdItalian)... or Languages(wdEnglishUS)  don't produce any error (but also no TRUE result for correct word)
0
 
LVL 11

Accepted Solution

by:
Steiner earned 400 total points
ID: 10711064
I had the same problem (using Word97), I used a workaround described on
http://support.microsoft.com/default.aspx?scid=kb;en-us;832124&Product=wrd

(although it's supposed for Word2000, so I had small changes to make)

But the principle should work: Insert the word in a new document, spellcheck the document and return the number of failure marks (0=Ok, >0=wrong).

Of course this one is very time consuming as everytime a new document is opened, so if you plan to use this function often, maybe you could use one document for all checkings.
0
 

Author Comment

by:yawnexp
ID: 10717910
Well, I tried the code poposed before:

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 testCheck()
   msgbox CheckSpellingWithLang("roi", wdFrench)
   msgbox CheckSpellingWithLang("method", wdFrench)
End Sub


But first I didn't receive any positive result. For any reason also my online spellchecker in any document itself didn't work any more.
So I removed all spell checking features (System settings/ software/ MS Word) and reinstalled them again.
Just to be sure I checked all above reported and ocurred errors concerning the spellchecking() function. No changes, except no error message any more.
So obviously Mircrosoft delivered a system bug (!) along with the CheckSpelling() function. Hope this problem is resolved in later versions. Does anyone have a clue if the function works in Office 2002 or 2003?

Anyway, I tried the above mentioned code again and... bull's eye !! It' working!
I can't evaluate the reduction in processing speed but a global doc variable should help. Set it up once, check all words, then remove it again.
Of course I don't only want to check the spelling but also get Spelling Suggestions: When
      Dim suggList As SpellingSuggestions: Set suggList = oDoc.Range.GetSpellingSuggestions
is added properly, the function can also return the suggestions list!

To be true: I encountered a similar checking method in the net already, but didn't follow it for complexity reasons and written in VB and not in VBA)

Thanks to y'all, now my project can be continued :-)
CU Jan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now