VBA code to change regional settings

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,215,844
Messages
6,127,252
Members
449,372
Latest member
charlottedv

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