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

大兔子大兔子 提交于 2019-12-21 20:46:07

问题


I have a macro that generates an MS Word report from an MS Excel spreadsheet. The styles I use in the report are coded in English in the Macro.

Some of my team have their MS Office display language set to France (this is not weird, I work in France). My macro thus doesn't work as the style title (in English) is used to set the styles. e.g. I'm telling MS Word to use style "List Bullet 1" whereas the corresponding style in MS Word is "Liste à puce 1" so no match is found.

So my question is, how can I detect the MS Office display language and then set the style value in the correct language ?

Another question is, is there another way of referencing styles besides the title ?

Best regards,

Colm


回答1:


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


来源:https://stackoverflow.com/questions/11719754/how-can-i-identify-the-display-language-i-e-toolbars-menus-used-by-ms-office

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