[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-03-27
7
Medium Priority
?
1,701 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 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
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

873 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