How can I identify the display language (i.e. toolbars/menus) used by MS Office in Visual Basic?

我是研究僧i 提交于 2019-12-04 14:41:12

Colmatairbus,

GSerg's link provides excellent reference to how Microsoft VBA deals with language settings.

Using VBA, you can reference the language in word for a variety of purposes. For instance, you can determine the current language, store it in a variable, and display it in a messagebox:

    Sub LanguageMessageBox()

        CurrentLanguage = Selection.LanguageID
        MsgBox (CurrentLanguage)

    End Sub

You can find the languageID list here: http://msdn.microsoft.com/en-us/library/bb213877(v=office.12).aspx

You can also simply reference the language itself, especially if you do not want to look the numbers or use the numbers in some algorithmic way:

Sub LanguageMessageBox()

    CurrentLanguage = Selection.LanguageID
    MsgBox (Languages(CurrentLanguage))

End Sub

As for changing the language settings, you can easily change the language settings by referencing the languageIDs:

Sub ChangeLanguage()

    ' 1033 is wdEnglishUS
    ' 1034 is wdSpanish        
    ' 1036 is wdFrench

    If Selection.LanguageID = 1033 Then
        Selection.LanguageID = 1034
        Else
        Selection.LanguageID = 1036
    End If

'Set the grammar dictionary for error checking purposes
Set dicGrammar = Languages(Selection.LanguageID).ActiveGrammarDictionary

End Sub
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!