Opening a Dictionary File Using a Macro in 2007

J

johnno

I hope this is the right forum for this question. If not please redirect me
and accpet my apologies.

In all my previous versions of Word (2003 and earlier) I created an AutoNew
macro for each template, and they would open dictionaries associated with
that template. I'm not a programmer, and I created the macros using Create
Macro.

In Word 2007 it just won't work for me, and the only line in the code of the
Macro is the name of the macro. E.g. if I name the macro
"OpenItalianDictionary" it just shows me those words in the macro.

Any ideas what I should do? Also, is there a way of transferring macros from
2003 to 2007?

Thanks
 
D

Doug Robbins - Word MVP

Your autonew macros should work in just the same way if you use Word 2007 to
create a new document from one of your templates.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

johnno

I wish it did, but it won't.

Here's the message I get from Word 2007 when I open an old document and the
AutoOpen macro of that template runs:

Run-time error '91':

Object variable or With block variable not set

When I click on Debug it shows me the macro with the line that selects the
dictionaly highlighted. I've checked, and there's no mistake in the name or
location.

I've tried making a new AutoNew macro except it won't record the part in
Options when I select the dictionary.

Any ideas?
 
D

Doug Robbins - Word MVP

Show us the code in the original macro

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

johnno

Here's the entire macro (in case you're wondering, I've checked and the
dictionary file is in the specified folder):

Sub AutoOpen()
'
' AutoOpen Macro
' Macro recorded 2/12/2006 by Johnno
'
With Options
.CheckSpellingAsYouType = True
.CheckGrammarAsYouType = False
.SuggestSpellingCorrections = True
.SuggestFromMainDictionaryOnly = False
.CheckGrammarWithSpelling = False
.ShowReadabilityStatistics = False
.IgnoreUppercase = True
.IgnoreMixedDigits = True
.IgnoreInternetAndFileAddresses = True
.AllowCombinedAuxiliaryForms = True
.EnableMisusedWordsDictionary = True
.AllowCompoundNounProcessing = True
.UseGermanSpellingReform = True
End With
ActiveDocument.ShowGrammaticalErrors = True
ActiveDocument.ShowSpellingErrors = True
Languages(wdEnglishUS).SpellingDictionaryType = wdSpelling
With CustomDictionaries
.ClearAll
.Add( _
"C:\Documents and Settings\Johnno\Application
Data\Microsoft\UProof\Special.dic" _
).LanguageSpecific = False
.ActiveCustomDictionary = CustomDictionaries.Item( _
"C:\Documents and Settings\Johnno\Application
Data\Microsoft\UProof\Special.dic" _
)
End With
End Sub
 
D

Doug Robbins - Word MVP

Your code runs OK if you delete the

..LanguageSpecific = False

which with it being set to False, effectively makes the setting redundant
anyway.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

johnno

Thanks for that, but I'm only half way there.

Deleting that line allowed the code to run without causing an error (btw,
how on earth would a line like that get in there in the first place?) but it
still didn't open the dicionary.

Any way of fixing that?
 
D

Doug Robbins - Word MVP

The macro recorder is well know for including a lot of unnecessary bits in
the recorded code and while such recorded macros do not usually cause
errors, they often do not do what the user was hoping they would do.

Did you delete the whole command or just the .LanguageSpecific = False?

You will still need

..Add( "C:\Documents and Settings\Johnno\Application
Data\Microsoft\UProof\Special.dic" )

but see the first paragraph above. The macro may run, but it may not do
what you want it to.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

johnno

I deleted only the words you advised.

So after all that, how do I open make one dictionary file active using a
macro in Word 2007? I can't just record keystrokes because, as I've already
said, when it runs it does nothing.

Thanks
 
D

Doug Robbins - Word MVP

How do you know it is not active?

If you run the following code (change the file path to suit your case), it
will tell you the name of the ActiveCustomDictionary

With Options
.CheckSpellingAsYouType = True
.CheckGrammarAsYouType = False
.SuggestSpellingCorrections = True
.SuggestFromMainDictionaryOnly = False
.CheckGrammarWithSpelling = False
.ShowReadabilityStatistics = False
.IgnoreUppercase = True
.IgnoreMixedDigits = True
.IgnoreInternetAndFileAddresses = True
.AllowCombinedAuxiliaryForms = True
.EnableMisusedWordsDictionary = True
.AllowCompoundNounProcessing = True
.UseGermanSpellingReform = True
End With
ActiveDocument.ShowGrammaticalErrors = True
ActiveDocument.ShowSpellingErrors = True
Languages(wdEnglishUS).SpellingDictionaryType = wdSpelling
With CustomDictionaries
.ClearAll
.Add ("C:\Documents and Settings\Doug Robbins\Application
Data\Microsoft\UProof\Special.dic")
.ActiveCustomDictionary = CustomDictionaries.Item( _
"C:\Documents and Settings\Doug Robbins\Application
Data\Microsoft\UProof\Special.dic" _
)
End With
MsgBox CustomDictionaries.ActiveCustomDictionary.Name


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

johnno

I know it's not active because after I open the file I check in
Proofing>Custom Dictionaries, and the checkbox is not checked.
 
J

johnno

Been away for a few days.

Does the dearth of replies mean that no one knows how to help me?
 
D

Doug Robbins - Word MVP

What did the message box

MsgBox CustomDictionaries.ActiveCustomDictionary.Name

display?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

johnno

I must have done something wrong, because the Message Box shows me whatever
name of dictionary that I enter in the code you gave me, evcen if that
dictionary doesn't exist!
 
J

johnno

Sorry but my last post was incomplete. I just discovered that the code you
gave me below creates a dictionary with whatever name I specify, but it does
not make that dictionary active. And it also makes all the dictionaries that
I have non-active, even after I activated them manually earlier.
 
D

Doug Robbins - Word MVP

It's the

.ClearAll

command in the code that is causing all of the dictionaries to be unchecked.

I've come to the conclusion that there is a bug in Office 2007 that I will
report.

I have discovered that if I remove all of the dictionaries from the
Dictionary List in the Custom Dictionaries dialog, then when the code is
run, and the Custom Dictionaries dialog is accessed, the dictionary that is
added by the code appears with the box checked and the (Default) added.

After accessing the dialog, it is possible to add a word to the dictionary.
Before accessing it, it is not.

Also, when running the code from the Visual Basic Help file

Dim dicCustom As Dictionary

Application.CustomDictionaries.ClearAll

Set dicCustom = Application.CustomDictionaries _
.Add(FileName:="C:\Program Files" _
& "\Microsoft Office\Office\Home.dic")
Application.CustomDictionaries.ActiveCustomDictionary = dicCustomwith a
Home.dic file in the folder specified, it gives an error message:

Run-time error '4684':

Word can only add words to a custom dictionary.

In spite of the error, it does however add the dictionary and check it as
mentioned above.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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