Controlling Windows Regional Settings from VBA

GlennG

Board Regular
Joined
May 20, 2002
Messages
80
Hello all,

Is it possible to control Windows regional settings ? Working with 2 languages (and corresponding number formats), I often have to change settings from the Windows regional settings control panel. I want to change certain settings like the decimal symbol (ie from period to comma and vice versa ). Is this possible ? Can anyone provide me with an example ?

Thank you for your time....


PS I just love this site; it's so full of knowledgeable people with tremendous talent ! Thank you all for your input !
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Glenn.
Provide a list of all of the changes you make. If you are adept or at least somehwat familiar with the windows API then I'll just post a single example and you may disregard the above. Is not difficult but you will need to do a bit of reading at MSDN or elswhere to find information about the many. many constants...

Tom


Here is a simple example of changing the decimal from . to , and back...

Code:
Private Declare Function SetLocaleInfo _
  Lib "kernel32" Alias "SetLocaleInfoA" ( _
  ByVal Locale As Long, _
  ByVal LCType As Long, _
  ByVal lpLCData As String) As Boolean

Private Declare Function GetUserDefaultLCID% Lib "kernel32" ()

Private Const LOCALE_SDECIMAL = &HE

Private Sub ChangeSettingExample()
'change the setting of the character displayed as the decimal separator.
    Call SetLocalSetting(LOCALE_SDECIMAL, ",") 'to change to ","
    'check your control panel to verify or use the
    'GetLocaleInfo API function
    Stop
    Call SetLocalSetting(LOCALE_SDECIMAL, ".") 'to back change to "."
End Sub

Private Function SetLocalSetting(LC_CONST As Long, Setting As String) As Boolean
    Call SetLocaleInfo(GetUserDefaultLCID(), LC_CONST, Setting)
End Function

The sub could simple be edited to pass a different constant representing various local settings. I would create a package group enumeration for each setting group or user group. You can also get to these settings by editing the registry using VB/VBA.


Constant's definitions may be read over here:

http://msdn.microsoft.com/library/d...y/en-us/wcelocal/htm/cereflctypeconstants.asp
 
Upvote 0
Controlling Windows Regional Settings from VBA (follow up)

Thanks TSTom,

That piece of code is a bit much for me. I hate to admit it, but I a newbee to VBA .....

I did find something interesting. I exported the registry entry to a text file with a .reg extention. The registry entries are all modifiable and best of all, when you double click that file, the registry is automatically undated with the correct parameters (ie the ones in the text .reg file which I modified. Everything is there and modifiable.

Granted it's not what I asked for, but it works ! Now if I could just execute this file via VBA; a shell function maybe.

Thanks for your input TsTom; you inspired me !

Glenn
 
Upvote 0
Actually yours is a great idea. I just like overcomplicating things. :)
Yes, use the shell function, open regedit.exe and the the associated .reg file
using the "S" switch(silent)

Create your settings files for each Regional Settings package you will deploy
with your workbook.

RegionSet1.reg for example
Use the following function to update the registry with this file...

Code:
Private FunctionRegUpdate(strRegFilePath As String) As Boolean
    If Shell("Regedit.exe /s " & strRegFilePath, vbNormalFocus) <> 0 Then
        ExampleRegistryImport = True
    End If
End Function

Use the function from within the same module as such:
Simply provide the path of the reg file.

Code:
Sub YourSub()
    Call ExampleRegistryImport("C:\WIN95\Desktop\RegionalSettingsPack_1.reg") 
End Sub

The function will return true if regedit was successfully opened. There is no way without the
API to know if the import was good but you can probably rest assured that it was. Test the
reg file by double-clicking it before referring to it in your code. Backup your registry first!

Tom
 
Upvote 0
hello, i need to change the regional and languages options of computer.

For exemple:


i have a computer with the options "Portuguese(Brazil)" and i want change for "English(United States)"

how can i do this with VBA?


thank's for help
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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