vba 如何在 Visual Basic 中识别 MS Office 使用的显示语言(即工具栏/菜单)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11719754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I identify the display language (i.e. toolbars/menus) used by MS Office in Visual Basic?
提问by carbontracking
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.
我有一个从 MS Excel 电子表格生成 MS Word 报告的宏。我在报告中使用的样式在宏中用英文编码。
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.
我的一些团队将他们的 MS Office 显示语言设置为法国(这并不奇怪,我在法国工作)。由于样式标题(英文)用于设置样式,因此我的宏不起作用。例如,我告诉 MS Word 使用样式“List Bullet 1”,而 MS Word 中的相应样式是“Liste à puce 1”,因此找不到匹配项。
So my question is, how can I detect the MS Office display language and then set the style value in the correct language ?
所以我的问题是,如何检测 MS Office 显示语言,然后以正确的语言设置样式值?
Another question is, is there another way of referencing styles besides the title ?
另一个问题是,除了标题之外,还有其他引用样式的方法吗?
Best regards,
此致,
Colm
科尔姆
采纳答案by HymanOrangeLantern
Colmatairbus,
科尔马空中客车,
GSerg's link provides excellent reference to how Microsoft VBA deals with language settings.
GSerg 的链接为 Microsoft VBA 如何处理语言设置提供了很好的参考。
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:
使用 VBA,您可以出于各种目的在 word 中引用该语言。例如,您可以确定当前语言,将其存储在一个变量中,然后将其显示在消息框中:
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
您可以在此处找到语言ID列表: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:
至于更改语言设置,您可以通过引用 languageID 轻松更改语言设置:
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