我正在尝试使用以下代码:
#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无法正常工作...
请帮助解决可能出现的问题, 最好, 贾塞克
当我使用带有“美国”区域设置的Windows但却无法正常工作时,我尝试使用“ fr-CA”而不是“ pl-PL”,并分配给userLocale = 1045。
目标是使此宏在Windows 10中正常工作。
答案 0 :(得分:1)
请注意,If SetThreadLocale(frCa) Then
会切换为frCa
,但是在注释之后的1行之后,您将 back 切换到SetThreadLocale userLocale
之前的状态(如果您阅读您链接的原始线程会告诉您确切的信息)。
因此,更改仅在这2条语句之间发生了很短的时间。
因此,可以将应该在更改后的语言环境上运行的代码放在以下两者之间:
If SetThreadLocale(frCa) Then
'put your code that should run in polish here
SetThreadLocale userLocale
End If
或要永久更改语言环境,请使用以下内容代替上述内容:
SetThreadLocale frCa