Solved

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

Posted on 2004-03-27
7
1,572 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:smozgur
smozgur 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
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…

744 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

16 Experts available now in Live!

Get 1:1 Help Now