|
|
Question : How do i modify the List Seperator Character
|
|
I have a question regarding the regional settings on a PC.
I have two applications, one is an Excel workbook with lots of VBA and another is a Word document also with lots of VBA.
The Word document will only work properly when the LIST SEPARATOR is set to ; The Excel sheet will only work properly when the LIST SEPARATOR is set to ,
This is set via:
Start Control Panel Regional & Language Options Regional Options Tab Customize List Separator , or ; depending on application.
Its not possible to modify things to make it work with a general list separator... tried that earlier ... see
http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_21817252.html
However, my question is, is there any way of setting the regional settings via VBA when the sheet opens so that an error does not occur ?
Alternatively can i check the value of the List Seperator and if its not a ; as required then use a pop up box to issue a warning to the user.
Thanks
Gordon
|
Answer : How do i modify the List Seperator Character
|
|
Found a sample on the net that was originally taken from winapi.txt, and tweaked it some!
You can retrieve and set regional settings using the following APIs....
Declare Function GetLocaleInfo Lib "kernel32" Alias _ "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, _ ByVal lpLCData As String, ByVal cchData As Long) As Long
Declare Function SetLocaleInfo Lib "kernel32" Alias _ "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, _ ByVal lpLCData As String) As Boolean
Declare Function GetUserDefaultLCID% Lib "kernel32" ()
'parm value Public Const LOCALE_SLIST = &HC
'Subs to retireve / set:
Public Sub Get_locale() ' Retrieve the regional setting
Dim Symbol As String Dim iRet1 As Long Dim iRet2 As Long Dim lpLCDataVar As String Dim Pos As Integer Dim Locale As Long Locale = GetUserDefaultLCID() iRet1 = GetLocaleInfo(Locale, LOCALE_SLIST, _ lpLCDataVar, 0) Symbol = String$(iRet1, 0) iRet2 = GetLocaleInfo(Locale, LOCALE_SLIST, Symbol, iRet1) Pos = InStr(Symbol, Chr$(0)) If Pos > 0 Then Symbol = Left$(Symbol, Pos - 1) MsgBox "Regional Setting = " + Symbol End If
End Sub
Public Sub Set_locale() 'Change the regional setting
Dim Symbol As String Dim iRet As Long Dim Locale As Long
Locale = GetUserDefaultLCID() 'Get user Locale ID Symbol = "-" 'New character for the locale iRet = SetLocaleInfo(Locale, LOCALE_SLIST, Symbol) End Sub
|
|
|
|
|