查找当前用户语言 [英] Find the current user language

查看:94
本文介绍了查找当前用户语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 vba 程序?

我需要以适当的语言显示表单。

I need this to show a form in an appropriate language.

推荐答案

p>我的初始代码(使用此 vbforum代码)假定Windows和Excel分享一个共同的语言 - 可能但不是防弹的。

My initial code (utilising this vbforum code) assumed that Windows and Excel share a common language - likely but not bulletproof.

更新

代码:


  1. 返回区域设置ID(LCID)。

  2. 从这个< a href =http://msdn.microsoft.com/en-us/goglobal/bb964664 =nofollow noreferrer> msft链接。

  3. 解析LCID使用正则表达式来获取语言。

  1. Returns the Locale ID (LCID).
  2. Looks up the LCID from this msft link.
  3. Parses the LCID using a regexp to get the language.

我的机器上的输出示例

代码将让用户知道访问LCID网站是否有任何错误或解析国家/地区

The code will let the user know if there are any errors in accessing the LCID website, or in parsing the country name.

    Sub GetXlLang()
        Dim lngCode As Long
        lngCode = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
        MsgBox "Code is: " & lngCode & vbNewLine & GetTxt(lngCode)
    End Sub

    Function GetTxt(ByVal lngCode) As String
        Dim objXmlHTTP As Object
        Dim objRegex As Object
        Dim objRegMC As Object
        Dim strResponse As String
        Dim strSite As String

        Set objXmlHTTP = CreateObject("MSXML2.XMLHTTP")
        strSite = "http://msdn.microsoft.com/en-us/goglobal/bb964664"

        On Error GoTo ErrHandler
        With objXmlHTTP
            .Open "GET", strSite, False
            .Send
            If .Status = 200 Then strResponse = .ResponseText
        End With
        On Error GoTo 0

        strResponse = Replace(strResponse, "</td><td>", vbNullString)
        Set objRegex = CreateObject("vbscript.regexp")
        With objRegex
            .Pattern = "><td>([a-zA-Z- ]+)[A-Fa-f0-9]{4}" & lngCode                    
            If .Test(strResponse) Then
                Set objRegMC = .Execute(strResponse)
                GetTxt = objRegMC(0).submatches(0)
            Else
                GetTxt = "Value not found from " & strSite
            End If
        End With
        Set objRegex = Nothing
        Set objXmlHTTP = Nothing
        Exit Function
ErrHandler:
        If Not objXmlHTTP Is Nothing Then Set objXmlHTTP = Nothing
        GetTxt = strSite & " unable to be accessed"
    End Function

这篇关于查找当前用户语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆