Changing the LanguageID property of all styles in a document.

D

david_alex_smith

Hello,

I require a macro to set all of the styles in a document to UK English for
spell-checking etc.

I've written the following VB:

Sub UKStyle()
For Each Sty In ActiveDocument.Styles
Sty.LanguageID = wdEnglishUK
Next
End Sub

This produces the following error when executed:

"That property is not available on that object."

This is puzzling me as it appears that the object is available in the API
docs. I can also change a single style with the following code:

ActiveDocument.Styles(1).LanguageID = wdEnglishUK

Any ideas why my code doesn't work?

Thanks.

Dave.
 
H

Helmut Weber

Hi David,

not each style has a LanduageID.

Try this:

Dim sty As Style
For Each sty In ActiveDocument.Styles
' MsgBox sty.NameLocal
On Error Resume Next
sty.LanguageID = wdEnglishUK
On Error GoTo -1
Next

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
T

Theo van der Ster

If you want this for all styles then it equals the entire document,
doesn't it? So why not do simply like this:

Selection.WholeStory
Selection.LanguageID = wdEnglishUK
Selection.Collapse

Hope this solves it.

Regards,
Theo
 
K

Klaus Linke

Hi Theo,

Yes, that would work fine for the moment.
I'd still prefer the style changes, since any text added later will be ok, too.

Regards,
Klaus
 
D

david_alex_smith

I agree Klaus. Thank you both for your help.

I have added the code to catch errors and it workd great now.

Thanks again.

Dave.
 

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