Solved

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

Posted on 2004-03-27
7
1,614 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

749 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