How to change the dictionary language for spellcheck
by D King » Fri, 24 Sep 2004 23:35:20 GMT
I need to know how to programmatically change the dictionary language for
spellcheck. I have the following code in my .net app which works great but
only checks spelling in the current word dictionary, I need to be able to
change this....any help is appreciated. Thanks.
Namespace SpellChecker
Public Class Spelling
Public Shared Function Check(ByVal TextToCheck As String) As String
TextToCheck = Trim(TextToCheck)
Try
' Create Word and temporary document objects.
Dim objWord As Object
Dim objTempDoc As Object
' Declare an IDataObject to hold the data returned from the clipboard.
Dim iData As IDataObject
' If there is no data to spell check, then exit sub here.
If TextToCheck = "" Then
Exit Function
End If
objWord = New Word.Application
objTempDoc = objWord.Documents.Add
objWord.Visible = False
' Position Word off the screen...this keeps Word invisible
objWord.WindowState = 0
objWord.Top = -3000
' Copy the contents of the textbox to the clipboard
Clipboard.SetDataObject(TextToCheck)
' With the temporary document perform spell check
With objTempDoc
.Content.Paste()
.Activate()
.CheckSpelling()
' .CheckGrammar()
' After user has made changes, use the clipboard to
' transfer the contents back to the text box
.Content.Copy()
iData = Clipboard.GetDataObject
If iData.GetDataPresent(DataFormats.Text) Then
'Return the text..
Check = CType(iData.GetData(DataFormats.Text), _
String)
End If
.Saved = True
.Close()
End With
objWord.Visible = False
objWord.Quit()
MessageBox.Show("The spelling check is complete.", _
"Spell Checker", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
' Microsoft Word must be installed.
Catch COMExcep As COMException
MessageBox.Show( _
"Microsoft Word must be installed for Spell/Grammar Check " _
& "to run.", "Spell Checker")
Catch Excep As Exception
MessageBox.Show("An error has occured.", "Spell Checker")
End Try
End Function
End Class
End Namespace
Re: How to change the dictionary language for spellcheck
by Cindy M -WordMVP- » Tue, 28 Sep 2004 22:38:19 GMT
Hi D,
As a general rule, Word prefers to use the dictionary for the language
formatting applied to the currently selected text in the document. Below my
signature, I've copied a message from someone who did manage to get this to
work; I've never tested it, however.
Cindy Meister
Automating spell check from outside Word
From: XXXX@XXXXX.COM (Richard Pearce)
Newsgroups: microsoft.public.word.international.features
Subject: MainDictionary parameter of CheckSpelling method does not work:
Workaround
Date: 1 Mar 2002 04:39:33 -0800
I've been looking at using Word 2000 Visual Basic to programmatically
spell check text in a foreign language (i.e. a language other than the
operating system one), without using a Document object and all the
dialog interaction that entails. Example: My Windows installation is
English, and I want to find out if "Dien" is a valid German word
without bringing up the Spelling and Grammar dialog.
My first attempt used Application.CheckSpelling, passing the NameLocal
of the desired language to the MainDictionary parameter. As several
old threads point out, this doesn't work - the MainDictionary
parameter is ignored and the spell check is performed in the operating
system language, like it or not.
I've found a different way of approaching the problem, using the
SpellingSuggestions collection. The following code achieves the
desired result (apologies if the code is inelegant or inefficient -
I'm not a VB programmer):
SpellWord = "Dien"
DictLang = wdGerman
MainDict = Languages(DictLang).NameLocal
Set Suggest = GetSpellingSuggestions(Word:=SpellWord, _
CustomDictionary:="Custom.dic", MainDictionary:=MainDict)
If Suggest.SpellingErrorType = wdSpellingCorrect Then
MsgBox "Spelling OK"
Else
If Suggest.Count = 0 Then MsgBox "No Suggestions"
End If
For i = 1 To Suggest.Count
MsgBox Suggest.Item(i).Name
Next i
Re: How to change the dictionary language for spellcheck
by RG90TmV0TWFuaWFj » Wed, 29 Sep 2004 01:13:05 GMT
Thanks Cindy, actually I re-wrote the code from scratch as a class library
which can be used with any .net application. For the langague issue, I used
Range.LanguageID = wdWhateverLangauge
The full source code and project are available on my web site if anyone
wants it:
http://www.**--****.com/
D.
Similar Threads:
1.Spellcheck language dictionary
2.change languages for spellcheck
Once upon a time I changed the spellchecker language in Excel to
Spanish, to check a translation file. Now, when I try to change back
to English, I go to Tools, Language, and get an error message.
" 'Set-language' cannot be accessed". I re-installed both Excel and
the Proofing tools, and downloaded the latest patch, but the problem
persists. Any ideas about what's screwed up, and how to fix it?
I have no problem changing spellcheck language in Word.
3.How to change spellcheck language
I can not change the language prefrence for outlook express. It only gives me
french as an option. How do I change it to english.
4.Change Language in OutLook Express for Spellcheck
I installed Office 2007 and for some reason OutLook Express now wants to do
spellcheck in French. I tried to change the spellcheck language in OutLook
Express but there is no other language option in the dropdown menu except
French. When I check the editing language in Word 2007 it is set to U.S.
English and Word spellchecks documents using the English dictionary.
I have SP1 installed for Office 2007 and I am running XP with the lastest
updates. Any ideas on how I can get my English dictionary in OutLook Express
back?
5.Change spellcheck language?
All of a sudden my IE6 spellcheck started telling me all the words were
spelled wrong. Upon checking I discovered that some how the spellcheck
language got changed to French! I pulled down the arrow to change the
language back to English and French was the only choice listed! Help, how
do I get my English choice back?
Thanks in advance... Bob
6. Can automatic updates be changing my spellcheck dictionaries
7. Spellcheck language in word keeps changing by itself
8. Spellcheck language keeps changing as I check!