Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Controlling Windows Regional Settings from VBA

  1. #1
    Board Regular
    Join Date
    May 2002
    Location
    Montreal, Canada
    Posts
    80
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Controlling Windows Regional Settings from VBA

    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 !

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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/de...econstants.asp

  3. #3
    Board Regular
    Join Date
    May 2002
    Location
    Montreal, Canada
    Posts
    80
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default 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

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  5. #5
    New Member
    Join Date
    Feb 2012
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Controlling Windows Regional Settings from VBA

    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

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •