Add a word to MS Word Dictionay via VBScript

S

StephenMcC

Hi All,
I'm trying to figure out how to do the above. I have developed a spell
checker app which is a client/server solution using a mix of JS, but mainly
for the MSWord integration, VBScript. The app has all the main functionality,
in which there is an option to ignore a desired word etc. But I'd like to
give the options to 'Ignore & Add to Dictionary' & 'Add to Dictionary', but
I'm finding it difficult to find a solution, or an example I can extend. From
what I've read this might get a bit complex as one might have to specify the
dictionary to use (main or custom) and specify a location of where this is
stored, while I am only interested in using/adding to the main Word
dictionary. The app is rolled out to quite a few users so I'd like to avoid
this complexity if possible. The app is more or less done but this would
complete it, so any help is much appreciated.
Thanks in advance,
Stephen.
 
J

Jay Freedman

Hi Stephen,

The first point to make is that you _can't_ add to the main dictionary. That
is an unmodifiable binary file. The only way to add words to the list of
recognized spellings is to add them to a custom dictionary (presumably the
default custom dictionary, but there can be more than one).

The list of active custom dictionaries is maintained in the registry key

HKEY_CURRENT_USER\Software\Microsoft\Shared Tools\Proofing Tools\Custom
Dictionaries

The names of the values are numbers (1, 2, ...) and the contents are the
names of the files. If the file name doesn't include a path, then it's in
the default proofing folder, %appdata%\Microsoft\Proof.

Adding a word to a custom dictionary is simplicity itself, compared to
locating the correct file. It's simply a plain-text file with one word per
line, each line ending with a carriage return [Chr(13)]. The words are
usually sorted alphabetically, but that isn't necessary for the spelling
checker.

One more hurdle, if your script might change the dictionary while Word is
running: Word (and probably other Office programs) caches the contents of
the custom dictionary. Changes you make externally aren't reflected in the
current document until the dictionary is reloaded and the "Recheck document"
button in the Options dialog is clicked. One way to reload it, of course, is
to restart Word, but users get upset. ;-) In the GUI, you can go to the
Tools > Options > Spelling > Custom Dictionaries dialog and click the
Default button to reload the dictionary, then click the "Recheck document"
button. I don't know how you'd get an external script to do that, though.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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