View Single Post
 
Old 06-18-2025, 10:23 AM
Charles Kenyon Charles Kenyon is offline Windows 11 Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,536
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Thank you Andrew. I hope it helps Metta. It works for me here.
I've added a link to this thread in my article on the Microsoft Answers site: Proofing Language Keeps Changing - Solutions - How can I keep my proofing language from changing?
That article also contains code to change paragraph, character, and linked styles.

I keep a repository of code snippets in my Normal.dotm. I've added your macro to my own repository of code, I added some comments.
Code:
Sub SetLanguage()
  ' Changes all content and styles in the document to UK English spelling
  ' Andrew Lockton  2025-June-18
  ' https://www.msofficeforums.com/186297-post30.html
  '
  ' Only handles main story but also handles styles
  ' Does not change language in a blank document, needs some text
  '
  Dim aStyle As Style, iLingua As Integer
  ' Pick a language constant - this is set for English UK
  '   Language IDs https://docs.microsoft.com/en-us/office/vba/api/word.wdlanguageid
  '
  iLingua = wdEnglishUK
  '
  ' CYCLE THROUGH PARAGRAPH STYLES AND SET LANGUAGE
  For Each aStyle In ActiveDocument.Styles
    If aStyle.Type = wdStyleTypeParagraph Then
      aStyle.LanguageID = iLingua
    End If
  Next aStyle
  ' APPLY LANGUAGE TO TEXT ALREADY IN DOCUMENT MAIN LAYER
  ' SET TEXT AS NOT CHECED YET
  ' TURN OFF ANY SETTING TO NOT CHECK SPELLING AND GRAMMAR
  '
  With ActiveDocument
    .range.LanguageID = iLingua
    .range.NoProofing = False
    .SpellingChecked = False
    .GrammarChecked = False
    '.CheckSpelling ' CAN TURN THIS ON BY REMOVING FIRST COMMENT APOSTROPHE
  End With
  '
  ' CLEAR LIST OF WORDS PREVIOUSLY SET TO BE IGNORED DURING A SPELL CHECK
  Application.ResetIgnoreAll
End Sub
Private Sub StyleEnglishUK()
    '   Written 21 March 2018
    '   Charles Kenyon
    '   Intended to set all styles to EnglishUK, proofing, not automatitically update
    '   Language IDs https://docs.microsoft.com/en-us/office/vba/api/word.wdlanguageid
    '
    Dim aStyle As Style
    On Error Resume Next    ' Some styles have no language attribute and will give an error
    For Each aStyle In ActiveDocument.Styles
        Select Case aStyle.NameLocal
            Case "TOC 1", "TOC 2", "TOC 3", "TOC 4", "TOC 5", "TOC 6", "TOC 7", "TOC 8", "TOC 9", _
                 "Table of Figures", "Table of Authorities"
                Let aStyle.AutomaticallyUpdate = True
            Case Else
                Let aStyle.AutomaticallyUpdate = False
        End Select
        Let aStyle.LanguageID = wdEnglishUK
        Let aStyle.NoProofing = False
    Next aStyle
    Let ActiveDocument.UpdateStylesOnOpen = False    ' For information on using this line, see:
    '       http://www.shaunakelly.com/word/sharing/willmyformatchange.html
    On Error GoTo -1
End Sub
Note, I do not believe either of our macros will change the language in a blank document if the Windows language is set to be something different. There must be some text in the document. To set it for a new blank document requires a complex workaround.
Reply With Quote