PC Review


Reply
Thread Tools Rate Thread

How do I identify the current locale?

 
 
JR
Guest
Posts: n/a
 
      6th Oct 2009
Hi.

I need to be able to identify the locale that a system is using in order to
use and IF, THEN, ELSE or CASE statement. This is because a solution that
works for English doesn't work for French, and the solution for French
doesn't work for English.

Is there a simple piece of VBA that will question the system so that I can
then select which line of code to use depending on the locale?

Your help is greatly appreciated, thanks in advance.

JR
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      6th Oct 2009
I think you can use this...

LCID = Application.LanguageSettings.LanguageID(msoLanguageIDUI)

It returns the LCID as shown on this webpage...

http://www.science.co.il/Language/Lo...asp?s=codepage

It returns 1033 for my English(US) system (not sure which English code page
you were referring to) and it should return 1036 for a French(France) system
(although like the English code pages, there are several for French besides
France).

--
Rick (MVP - Excel)


"JR" <(E-Mail Removed)> wrote in message
news:AB83AFCB-29C6-4B95-9FD7-(E-Mail Removed)...
> Hi.
>
> I need to be able to identify the locale that a system is using in order
> to
> use and IF, THEN, ELSE or CASE statement. This is because a solution that
> works for English doesn't work for French, and the solution for French
> doesn't work for English.
>
> Is there a simple piece of VBA that will question the system so that I can
> then select which line of code to use depending on the locale?
>
> Your help is greatly appreciated, thanks in advance.
>
> JR


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      6th Oct 2009
Ron De Bruin deals with the subject here

http://www.rondebruin.nl/international.htm

Mike

"JR" wrote:

> Hi.
>
> I need to be able to identify the locale that a system is using in order to
> use and IF, THEN, ELSE or CASE statement. This is because a solution that
> works for English doesn't work for French, and the solution for French
> doesn't work for English.
>
> Is there a simple piece of VBA that will question the system so that I can
> then select which line of code to use depending on the locale?
>
> Your help is greatly appreciated, thanks in advance.
>
> JR

 
Reply With Quote
 
JR
Guest
Posts: n/a
 
      8th Oct 2009
Thank you both. Now I'll have to study Mr De Bruin's information and see
whether I can get my un-techie head round it. :-)

JR

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      8th Oct 2009
I can't test this as I don't have access to any computers in other
countries, but the following should return the language that the computer
running the code is set up for. So, using it should allow you to use a test
structure similar to this in your own code...

If UserLanguage() = "English" Then
' The computer running this code has English as its native language
ElseIf UserLanguage() = "French" Then
' The computer running this code has English as its native language
Else
MsgBox "You didn't test for this language: " & UserLanguage()
End If

Put all of the following in a Module (Insert/Module from the VB editor's
menu bar), then just call UserLanguage in your own code and it will return
the language set up in the regional settings for the computer running your
code...

Private 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

Private Const LOCALE_SNATIVELANGNAME As Long = &H4

Public Function UserLanguage() As String
Dim sReturn As String, lReturn As Long, dwLocaleID As Long, Code As Long
Code = LOCALE_SNATIVELANGNAME
dwLocaleID = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
lReturn = GetLocaleInfo(dwLocaleID, Code, sReturn, Len(sReturn))
If lReturn Then
sReturn = Space$(lReturn)
lReturn = GetLocaleInfo(dwLocaleID, Code, sReturn, Len(sReturn))
If lReturn Then UserLanguage = Left$(sReturn, lReturn - 1)
End If
End Function

--
Rick (MVP - Excel)


"JR" <(E-Mail Removed)> wrote in message
news:B7F8F34E-DEB8-4190-BD4B-(E-Mail Removed)...
> Thank you both. Now I'll have to study Mr De Bruin's information and see
> whether I can get my un-techie head round it. :-)
>
> JR
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Identify Current WS? =?Utf-8?B?RGF2ZSBCaXJsZXk=?= Microsoft Excel Programming 2 22nd May 2007 03:08 PM
force locale that differs from OS current culture Robert Ludig Microsoft Dot NET Framework Forms 2 12th Dec 2006 07:43 PM
Object doesn't support current locale setting: 'setlocale' Martin Eckart Microsoft Excel Programming 0 17th May 2005 09:41 AM
parsing the output using string.split and current locale.. Prasad Dabak Microsoft C# .NET 3 6th Apr 2005 06:24 AM
Terminal Client over VPN locale printer locale drives Sveeny Microsoft Windows 2000 Terminal Server Clients 2 26th Nov 2003 10:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:06 PM.