Modify language options from control panel using VBA

A

Alex St-Pierre

Hi,
I would like to modify the "Regional and Language Options"/"Standards and
Formats" from "french canadian" to "english canadian" using vba. I tried to
modify "LOCALE_IDEFAULTLANGUAGE" value but it doesn't work. I have pasted my
program. Does anyone know how to make it work.
Thank you!
Alex
Sub ModifyLanguage()
Dim Symbol As String
Dim iRet As Long
Dim Locale As Long
' Locale = GetSystemDefaultLCID()
Locale = GetUserDefaultLCID() 'Get user Locale ID
Symbol = "1009"
MsgBox GetInfo(LOCALE_IDEFAULTLANGUAGE) 'Give "0c0c"
Call SetLocaleInfo(Locale, LOCALE_IDEFAULTLANGUAGE, Symbol)
MsgBox GetInfo(LOCALE_IDEFAULTLANGUAGE) 'Still give "0c0c" ???
End Sub

Public Const LOCALE_USER_DEFAULT = &H400
Public Const LOCALE_SENGCOUNTRY = &H1002 ' English name of country
Public Const LOCALE_SENGLANGUAGE = &H1001 ' English name of language
Public Const LOCALE_SNATIVELANGNAME = &H4 ' native name of language
Public Const LOCALE_SNATIVECTRYNAME = &H8 ' native name of country
Public Const LOCALE_IDEFAULTCODEPAGE = &HB
Public Const LOCALE_IDEFAULTCOUNTRY = &HA
Public Const LOCALE_IDEFAULTLANGUAGE = &H9
Public Const LOCALE_ILANGUAGE = &H1
Public Const LOCALE_SLANGUAGE = &H2

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" ()

Public Function GetInfo(ByVal lInfo As Long) As String
Dim buffer As String, Ret As String
buffer = String$(256, 0)
Ret = GetLocaleInfo(LOCALE_USER_DEFAULT, lInfo, buffer, Len(buffer))
If Ret > 0 Then
GetInfo = Left$(buffer, Ret - 1)
Else
GetInfo = ""
End If
End Function
 
N

NickHK

Alex,
According to this article
http://vbnet.mvps.org/code/locale/setlocaleinfo.htm
LOCALE_IDEFAULTLANGUAGE is not a valid value for the LCType argument of
SetLocaleInfo.
And an MS article
http://msdn.microsoft.com/library/en-us/intl/nls_8rse.asp?frame=true
<Quote>
LOCALE_IDEFAULTLANGUAGE
Obsolete. Do not use. This value was provided so that partially specified
locales could be completed with default values. Partially specified locales
are now deprecated.
</Quote>

So, not sure how to change the locale, but not this way.

NickHK
 
A

Alex St-Pierre

Thanks Nick for the answer. I have read the articles and they suggest to ask
the user to modify the regional settings. Seems not to be possible to modify
it from VBA. So, if the report is created in French, I'll use GetLocalInfo to
verify if all numbers and date settings are correct. If not, I'll ask the
user to modify the settings to put "French (canadian)". I'll open the control
panel box directly in Excel using:
Sub test()
Dim Cmdl As String
Cmdl = "rundll32.exe shell32.dll,Control_RunDLL intl.cpl" + ",,5"
Shell Cmdl$, vbNormalFocus
End Sub
I expect it should be compatible with all versions of window.
Thank you!
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top