Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Reference the Path where Word's Custom Dictionaries are Located

Status
Not open for further replies.

DrGreg1408

Technical User
Feb 8, 2008
30
US
Hello everyone,

A lot of my work involves switching back and forth between English and Spanish while working in Microsoft Word. I wrote a macro that changes all the styles in the document to the Language of my choice and also changes the Active Custom Dictionary accordingly. This saves me a lot of mouse work.

I have one issue I have not been able to work out. I want to reference the path location where Word stores my custom dictionaries EVEN WHEN I DON'T HAVE A CURRENTLY ACTIVE DICTIONARY.

If I have an active dictionary, it's no problem. I just use the following:

[Application].[CustomDictionaries].[ActiveCustomDictionary].Path

However, this info request returns Run-time error 5825 "Object has been deleted" if I don't have a currently active custom dictionary.

Does anyone know how to reference that location, even when there is no currently active custom dictionary?

The following does not work:
[Options].DefaultFilePath(wdProofingToolsPath)
That returns the following path:
c:\program files\common files\microsoft shared\proof
which is NOT where Word saves my custom dictionaries.

They are saved at:
c:\users\greg\appdata\roaming\microsoft\proof

Any ideas about how to reference that location programmatically?

gsw
 
Firstly, I don't trust ActiveCustomDictionary.

Secondly, custom dictionaries can be anywhere; there is no path, just a default path and I'm not sure if that's available. You may have to walk the collection of custom dictionaries, checking the language (and location, if you want) of each, but ...

Why do you want to change the active one. The only reason I can imagine is if you have more than one for a language.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Hi gsw,

Here's one way:
Code:
Sub CustomDictionaryPath()
With Application.CustomDictionaries
  On Error GoTo NewPath
  MsgBox .ActiveCustomDictionary.Path
  Exit Sub
NewPath:
  .Add ("Tmp.Dic")
  MsgBox .ActiveCustomDictionary.Path
  .ActiveCustomDictionary.Delete
End With
End Sub
Cheers

[MS MVP - Word]
 
Tony,
Your question makes me wonder if my effort to change the active custom dictionary is necessary.

In my macro called SetLanguage I change the LanguageID value for every style in the document to the one corresponding to the user's choice that was made in a pop-up form.

After that, I change the active custom dictionary to the one I have set up to correspond with that language. The code is:

With Application.CustomDictionaries
.ClearAll
Set dicCustom = .Add(Filename:=gswGetDictionary(gvarLanguage))
.ActiveCustomDictionary = dicCustom
End With

Application.CheckLanguage = True

The gswGetDictionary returns a Dictionary type if it finds the dictionary. The code is

With fsSearch
.Filename = "*.dic"
.LookIn = cstrCustomDictionaryPath
.Execute
For intCounter = 1 To .FoundFiles.Count
If InStr(.FoundFiles(intCounter), strLanguage) > 0 Then
'Found it!
gswGetDictionary = .FoundFiles(intCounter)
If Len(gswGetDictionary) > 0 Then
Exit For
End If
End If
Next intCounter
End With

I would like to dynamically reference the path to my custom dictionaries instead of using a hard-coded constant (cstrCustomDictionaryPath in this case).

msvtopod,
Your solution works!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top