Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-03-27
7
Medium Priority
?
1,683 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 120 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 280 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 1600 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
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 a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.

609 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