Programmatically add words custom dictionary problem

L

Leon

There is no VBA way to add words to a custom dictionary, so I add them
programmatically from my Add-in (with good old fopen/fwrite etc.).

Words appear in the active custom dictionary, but MSWord is not
updating the red underlined markings (unless MSWord is closed and
reopened again.)

So I need a way to kick MSWord so it will reload the custom
dictionary.
Is there a way to notify MSWord that its active custom dictionary has
been changed?

Thanks,
Leon Post
 
P

Peter Hewett

Hi Leon

Try this to see if this will do what you want:

Public Sub ResetCustomDictionary()
Dim strDictionary As String

' Try to get Word to take note of the changes made to the custom dictionary

With CustomDictionaries
If IsObjectValid(.ActiveCustomDictionary) Then

' Save this info as we need to add the custom dictionary back in
strDictionary = .ActiveCustomDictionary.Path & _
"\" & .ActiveCustomDictionary.Name

' Clear the current custom dictionary and then put it back again
.ClearAll

' <-----Make your changes to the custom dictionary here----->

' Reinstate original custom dictionary
.Add strDictionary
End If
End With
End Sub

HTH + Cheers - Peter


(e-mail address removed) (Leon), said:
 
H

Helmut Weber

Hi Leon,
if you update the dictionary the way you said,
and remove it afterwards,
and reactivate it again, the changes are recognized.
Like this, unfortunately in a german environment,
and probably ".clear all", because there was no dictionary at all,
after removing the only one I got.
With CustomDictionaries
.ClearAll
.Add("C:\WINDOWS\Anwendungsdaten\Microsoft\Proof\co-e.dic"). _
LanguageSpecific = False
.ActiveCustomDictionary = CustomDictionaries.Item( _
"C:\WINDOWS\Anwendungsdaten\Microsoft\Proof\co-e.dic")
End With
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
L

Leon

Thanks for your responses (both Helmut and Peter)

Tried your suggestions but still no success.
It will probably work if a new custom dictionary is added with the new
word(s), but I just want to add the words to the active custom
dictionary.

What I do:

1.Store the names of all Dictionary objects in CustomDictionaries
2.Store the name of the ActiveCustomDictionary
3.Calling ClearAll on CustomDictionaries
4.Add words to the custom dictionary programmatically
5.Call Add on CustomDictionaries for all Dictionary names stored in
step 1
(so I don't add new-named dictionaries).
6.Set the ActiveCustomDictionary property with the Dictionary object
(which is named as the one stored in step 2).

I expected Word should be triggered by steps 3 and 5 and was hoping
this would force a recheck using the extended custom dictionary, but
nothing seems to happen. Words just added to the custom dictionary
stay marked as misspelled words...

Maybe it just isn't possible?

Regards and thanks anyway

Leon Post
 
H

Helmut Weber

Hi Leon,
it is impossible, which means, not with justifiable effort.
If you rename the custom dictionary to xx.txt and open it
with wordpad, you will hardly find any word. It is not a "real"
dictionary at all, but a mixture of rules and parts of words.
And the holders of the copyright, Houghton Mifflin Company and
Inso Corporation, probably did something against changing it.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top