h1

Word: Macro to set the language for ALL styles

September 21, 2018

One of the issues with setting the language for a Word document is that DOESN’T change the language set for the styles. If you’re lucky, your styles use the same language as your default language, but sometimes they don’t (especially if the document has come from authors in other countries). This can result in some strange behaviour under specific circumstances.

I have a macro for setting the language for all ‘ranges’ in a document, but I needed something to change the language settings for ALL styles in one command. After a bit of internet sleuthing, I came across an answer that looked promising and modified it to suit my purposes. It works! I tested it on a sample document, where I’d set the language for Normal to Alsatian, for Heading 1 to Afrikaans, and for Heading 2 to English (US). The only text I had in the document used Normal style, but that didn’t matter—the language settings for the styles still changed to the one I’d specified in the macro. In my case, that’s English (Australian) [in VBA code that’s wdEnglishAUS].

The only thing you need to change in this macro is the LanguageID. Here are some common ones for English:

  • wdEnglishAUS
  • wdEnglishCanadian
  • wdNewZealand
  • wdEnglishSouthAfrica
  • wdEnglishUK
  • wdEnglishUS.

Here’s the macro (copy it—some of it may go off the page, so if you type it you may miss some):

Sub ChangeLangStyles()

' Macro to change language in styles
' Adapted from Macropod (17 July 2012)
' http://www.vbaexpress.com/forum/showthread.php?42993-Solved-Macro-to-change-all-styles-to-a-specific-language

Dim oDoc As Document, oSty As Style
Set oDoc = ActiveDocument
    With oDoc
        For Each oSty In .Styles
            On Error Resume Next
            oSty.LanguageID = wdEnglishAUS
            On Error GoTo 0
        Next
    End With
End Sub

I adapted it from one shared by Macropod back in July 2012: http://www.vbaexpress.com/forum/showthread.php?42993-Solved-Macro-to-change-all-styles-to-a-specific-language, and full acknowledgement goes to him.

[Links last checked September 2018]

2 comments

  1. […] I needed to set the language for all elements of a Word 2007 template to English (Australia). I could set the language for the body of the document easily enough via a simple macro, but this didn’t set the language for the headers, footers, text boxes, or the styles (yes, you can set the language for a style!). (Update September 2018: I now have a macro for setting the language for all styles at once: https://cybertext.wordpress.com/2018/09/21/word-macro-to-set-the-language-for-all-styles/) […]


  2. […] Styles: There’s an option to set the language for EVERY style! By default, no language is set. But if you think a setting on a style may be the issue, check the style. Display the Styles pane, right-click on the style and select Modify. On the Modify Style dialog box, click Format > Language to see what language — if any — is set for that particular style. Don’t forget that some styles inherit properties from other styles, so the language may not be set on the style you’re looking at. Also, if Do not check spelling or grammar is set for a particular style, that explains why some sections of your document may be skipped when you run the spell checker. (Update September 2018: I now have a macro to set the language for ALL styles at once: https://cybertext.wordpress.com/2018/09/21/word-macro-to-set-the-language-for-all-styles/) […]



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: