我正在尝试使用以下代码:
#If VBA7 Then
Private Declare PtrSafe Function SetThreadLocale Lib "kernel32" _
(ByVal Locale As Long) As Boolean
Private Declare PtrSafe Function GetUserDefaultLCID Lib "kernel32" () As Long
Private Declare PtrSafe Function LocaleNameToLCID Lib "kernel32" _
(ByVal lpName As LongPtr, dwFlags As Long) As Long
#Else
Private Declare Function SetThreadLocale Lib "kernel32" (ByVal Locale As Long) As Boolean
Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
Private Declare Function LocaleNameToLCID Lib "kernel32" _
(ByVal lpName As LongPtr, dwFlags As Long) As Long
#End If
Private Sub Test()
'Get the locale identifier for French (Canada)
Dim frCa As Long
frCa = LocaleNameToLCID(StrPtr("fr-CA"), 0)
'Make sure there function succeeded.
If result = 0 Then
'Cache the current locale
Dim userLocale As Long
userLocale = GetUserDefaultLCID
'Switch to French (Canada)
If SetThreadLocale(frCa) Then
'en français
'...
'switch back
SetThreadLocale userLocale
End If
End If
End Sub发自链接:
Change region format to another language with VBA
我正在寻找类似的解决方案,但这不是上面的工作。我尝试将区域设置更改为美国设置,并返回到波兰的区域设置(windows默认设置)。
来自GetUserDefaultLCID = 1045,US = 1033的波兰式设置,但宏正在运行,没有任何结果。(无错误,无更改)。有点像SetThreadLocale不工作了..。
请帮助可能出错的地方,Best,Jacek
我尝试使用"fr-CA“"pl-PL”代替“fr-CA”,并将其赋值给userLocale = 1045,当我使用windows与我们的区域设置,但不起作用。
目标是让这个宏在windows10中工作。
发布于 2019-02-05 20:22:50
请注意,If SetThreadLocale(frCa) Then切换为frCa,但在一行之后(注释之后),您将切换回SetThreadLocale userLocale之前的状态(如果您阅读您链接的原始线程,它将确切地告诉您这一点)。
因此,在这两个语句之间,变化只发生在很短的时间内。
因此,要么将应该在更改后的区域设置上运行的代码放在这两者之间:
If SetThreadLocale(frCa) Then
'put your code that should run in polish here
SetThreadLocale userLocale
End If或者,要永久更改区域设置,请使用以下代码而不是上面的代码:
SetThreadLocale frCahttps://stackoverflow.com/questions/54533797
复制相似问题