VBA code to change regional settings

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Ok Guys,

i found this code from here:
https://stackoverflow.com/questions...ZAxBwAYgT_lqB-Kc9JQA6qZAkdP7hySkx34tlnO9W5lNc

but this is not working for me.

Code:
Option ExplicitDim result


#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("en-US"), 0)
    'Make sure there function succeeded.
    If result = 0 Then
        'Cache the current locale
        Dim userLocale As Long
        userLocale = GetUserDefaultLCID
        SetThreadLocale 1045
        'Switch to French (Canada)
        If SetThreadLocale(frCa) Then
            'en français
            '...
            'switch back
            SetThreadLocale userLocale
        End If
    End If
End Sub

i tried to change "fr-CA" but this is not working.

userLocale = GetUserDefaultLCID is a long for Polish language = 1045, for English (United States) it is 1033.
How to set up?


SetThreadLocale 1033 should change windows settings for US, and 1045 should change it for 1033.

Can anybody help?

Best,
Jacek
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top