Informations LangueSysteme

Magic_Doctor

XLDnaute Barbatruc
Renvoie la langue du PC
VB:
Function LangueSysteme$()
'Détecte la langue du poste de l'utilisateur

On Error GoTo FunctionErreur
Dim CodeLangueSysteme As Single

    'Trouver le code de la langue
    CodeLangueSysteme = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
    
    'Associer le code à la langue (liste complète)
    Select Case CodeLangueSysteme
        Case 1036, 2060, 11276, 3084, 9228, 12300, 15372, 5132, 13324, 6156, 14348, 58380, 8204, 10252, 4108, 7180: LangueSysteme = "Français"
        Case 1033, 2057, 3081, 10249, 4105, 9225, 15369, 16393, 14345, 6153, 8201, 17417, 5129, 13321, 18441, 7177, 11273, 12297: LangueSysteme = "Anglais"
        Case 1031, 3079, 5127, 4103, 2055: LangueSysteme = "Allemand"
        Case 2052, 4100, 1028, 3076, 5124: LangueSysteme = "Chinois"
        Case 1043, 2067: LangueSysteme = "Néerlandais"
        Case 1040, 2064: LangueSysteme = "Italien"
        Case 3082, 1034, 11274, 16394, 13322, 9226, 5130, 7178, 12298, 17418, 4106, 18442, 22538, 2058, 19466, 6154, 15370, 10250, 20490, 21514, 14346, 8202: LangueSysteme = "Espagnol"
        Case 1025, 5121, 15361, 3073, 2049, 11265, 13313, 12289, 4097, 6145, 8193, 16385, 10241, 7169, 14337, 9217: LangueSysteme = "Arabe"
        Case 1078: LangueSysteme = "Afrikaans"
        Case 1052: LangueSysteme = "Albanian"
        Case 1156: LangueSysteme = "Alsatian"
        Case 1118: LangueSysteme = "Amharic"
        Case 1067: LangueSysteme = "Armenian"
        Case 1101: LangueSysteme = "Assamese"
        Case 2092: LangueSysteme = "Azeri (Cyrillic)"
        Case 1068: LangueSysteme = "Azeri (Latin)"
        Case 1133: LangueSysteme = "Bashkir"
        Case 1069: LangueSysteme = "Basque"
        Case 1059: LangueSysteme = "Belarusian"
        Case 1093: LangueSysteme = "Bengali (India)"
        Case 2117: LangueSysteme = "Bengali (Bangladesh)"
        Case 5146: LangueSysteme = "Bosnian (Bosnia/Herzegovina)"
        Case 1150: LangueSysteme = "Breton"
        Case 1026: LangueSysteme = "Bulgare"
        Case 1109: LangueSysteme = "Burmese"
        Case 1027: LangueSysteme = "Catalan"
        Case 1116: LangueSysteme = "Cherokee"
        Case 1155: LangueSysteme = "Corsican"
        Case 1050: LangueSysteme = "Croatian"
        Case 4122: LangueSysteme = "Croatian (Bosnia/Herzegovina)"
        Case 1029: LangueSysteme = "Tchèque"
        Case 1030: LangueSysteme = "Danois"
        Case 1164: LangueSysteme = "Dari"
        Case 1125: LangueSysteme = "Divehi"
        Case 1126: LangueSysteme = "Edo"
        Case 1061: LangueSysteme = "Estonian"
        Case 1080: LangueSysteme = "Faroese"
        Case 1065: LangueSysteme = "Farsi"
        Case 1124: LangueSysteme = "Filipino"
        Case 1035: LangueSysteme = "Finnish"
        Case 1122: LangueSysteme = "Frisian"
        Case 1127: LangueSysteme = "Fulfulde"
        Case 1071: LangueSysteme = "FYRO Macedonian"
        Case 1110: LangueSysteme = "Galician"
        Case 1079: LangueSysteme = "Georgian"
        Case 1032: LangueSysteme = "Greek"
        Case 1135: LangueSysteme = "Greenlandic"
        Case 1140: LangueSysteme = "Guarani"
        Case 1095: LangueSysteme = "Gujarati"
        Case 1128: LangueSysteme = "Hausa"
        Case 1141: LangueSysteme = "Hawaiian"
        Case 1037: LangueSysteme = "Hebrew"
        Case 1081: LangueSysteme = "Hindi"
        Case 1038: LangueSysteme = "Hungarian"
        Case 1129: LangueSysteme = "Ibibio"
        Case 1039: LangueSysteme = "Icelandic"
        Case 1136: LangueSysteme = "Igbo"
        Case 1057: LangueSysteme = "Indonesian"
        Case 1117: LangueSysteme = "Inuktitut"
        Case 2108: LangueSysteme = "Irish"
        Case 1041: LangueSysteme = "Japanese"
        Case 1158: LangueSysteme = "K'iche"
        Case 1099: LangueSysteme = "Kannada"
        Case 1137: LangueSysteme = "Kanuri"
        Case 2144: LangueSysteme = "Kashmiri"
        Case 1120: LangueSysteme = "Kashmiri (Arabic)"
        Case 1087: LangueSysteme = "Kazakh"
        Case 1107: LangueSysteme = "Khmer"
        Case 1159: LangueSysteme = "Kinyarwanda"
        Case 1111: LangueSysteme = "Konkani"
        Case 1042: LangueSysteme = "Korean"
        Case 1088: LangueSysteme = "Kyrgyz (Cyrillic)"
        Case 1108: LangueSysteme = "Lao"
        Case 1142: LangueSysteme = "Latin"
        Case 1062: LangueSysteme = "Latvian"
        Case 1063: LangueSysteme = "Lithuanian"
        Case 1134: LangueSysteme = "Luxembourgish"
        Case 1086, 2110: LangueSysteme = "Malay"
        Case 1100: LangueSysteme = "Malayalam"
        Case 1082: LangueSysteme = "Maltese"
        Case 1112: LangueSysteme = "Manipuri"
        Case 1153: LangueSysteme = "Maori"
        Case 1146: LangueSysteme = "Mapudungun"
        Case 1102: LangueSysteme = "Marathi"
        Case 1148: LangueSysteme = "Mohawk"
        Case 1104: LangueSysteme = "Mongolian (Cyrillic)"
        Case 2128: LangueSysteme = "Mongolian (Mongolian)"
        Case 1121, 2145: LangueSysteme = "Nepali"
        Case 1044: LangueSysteme = "Norwegian (Bokmål)"
        Case 2068: LangueSysteme = "Norwegian (Nynorsk)"
        Case 1154: LangueSysteme = "Occitan"
        Case 1096: LangueSysteme = "Oriya"
        Case 1138: LangueSysteme = "Oromo"
        Case 1145: LangueSysteme = "Papiamentu"
        Case 1123: LangueSysteme = "Pashto"
        Case 1045: LangueSysteme = "Polish"
        Case 1046, 2070: LangueSysteme = "Portuguese"
        Case 1094: LangueSysteme = "Punjabi"
        Case 2118: LangueSysteme = "Punjabi (Pakistan)"
        Case 1131, 2155, 3179: LangueSysteme = "Quechua"
        Case 1047: LangueSysteme = "Rhaeto"
        Case 1048, 2072: LangueSysteme = "Romanian"
        Case 1049, 2073: LangueSysteme = "Russian"
        Case 1083: LangueSysteme = "Sami (Lappish)"
        Case 1103: LangueSysteme = "Sanskrit"
        Case 1084: LangueSysteme = "Scottish Gaelic"
        Case 1132: LangueSysteme = "Sepedi"
        Case 3098: LangueSysteme = "Serbian (Cyrillic)"
        Case 2074: LangueSysteme = "Serbian (Latin)"
        Case 1113, 2137: LangueSysteme = "Sindhi"
        Case 1115: LangueSysteme = "Sinhalese"
        Case 1051: LangueSysteme = "Slovak"
        Case 1060: LangueSysteme = "Slovenian"
        Case 1143: LangueSysteme = "Somali"
        Case 1070: LangueSysteme = "Sorbian"
        Case 1072: LangueSysteme = "Sutu"
        Case 1089: LangueSysteme = "Swahili"
        Case 1053, 2077: LangueSysteme = "Suédois"
        Case 1114: LangueSysteme = "Syriac"
        Case 1064: LangueSysteme = "Tajik"
        Case 1119: LangueSysteme = "Tamazight (Arabic)"
        Case 2143: LangueSysteme = "Tamazight (Latin)"
        Case 1097: LangueSysteme = "Tamil"
        Case 1092: LangueSysteme = "Tatar"
        Case 1098: LangueSysteme = "Telugu"
        Case 1054: LangueSysteme = "Thai"
        Case 2129, 1105: LangueSysteme = "Tibetan"
        Case 2163, 1139: LangueSysteme = "Tigrigna"
        Case 1073: LangueSysteme = "Tsonga"
        Case 1074: LangueSysteme = "Tswana"
        Case 1055: LangueSysteme = "Turkish"
        Case 1090: LangueSysteme = "Turkmen"
        Case 1152: LangueSysteme = "Uighur"
        Case 1058: LangueSysteme = "Ukrainian"
        Case 1056, 2080: LangueSysteme = "Urdu"
        Case 2115: LangueSysteme = "Uzbek (Cyrillic)"
        Case 1091: LangueSysteme = "Uzbek (Latin)"
        Case 1075: LangueSysteme = "Venda"
        Case 1066: LangueSysteme = "Vietnamese"
        Case 1106: LangueSysteme = "Welsh"
        Case 1160: LangueSysteme = "Wolof"
        Case 1076: LangueSysteme = "Xhosa"
        Case 1157: LangueSysteme = "Yakut"
        Case 1144: LangueSysteme = "Yi"
        Case 1085: LangueSysteme = "Yiddish"
        Case 1130: LangueSysteme = "Yoruba"
        Case 1077: LangueSysteme = "Zulu"
        Case 1279: LangueSysteme = "HID (Human Interface Device)"
        
        Case Else: LangueSysteme = ""
    End Select
    
    Exit Function

FunctionErreur:
LangueSysteme = ""

End Function
 

Bernard_XLD

XLDnaute Barbatruc
Membre du Staff
Bonsoir Magic_Doctor, le forum

Une autre façon !

Bien cordialement, @+
VB:
Private Declare PtrSafe Function GetSystemDefaultLangID Lib "kernel32" () As Long
Private Declare PtrSafe Function VerLanguageName Lib "kernel32" Alias "VerLanguageNameA" (ByVal wLang As Long, ByVal szLang As String, ByVal nSize As Long) As Long
Function Langue_Systeme$()
    Dim Ident$, Nom_Langue$
    Ident = "&H" & Right(Hex(GetSystemDefaultLangID()), 3)
    Nom_Langue = String(255, 0)
    VerLanguageName CLng(Ident), Nom_Langue, Len(Nom_Langue)
    Nom_Langue = Left$(Nom_Langue, InStr(1, Nom_Langue, Chr$(0)) - 1)
    Langue_Systeme = Nom_Langue
End Function
 

Magic_Doctor

XLDnaute Barbatruc
Bonjour Yeahou,

Je me doutais bien qu'on pouvait faire nettement plus simple. Le problème, c'est que chez moi, ça ne marche pas. Peut-être ma version d'Excel (2007 !!!).
 
Dernière édition:

patricktoulon

XLDnaute Barbatruc
Bonjour
pour les version 32 (2003,2007) il suffit d'adapter les api
VB:
#If VBA7 Then
Private Declare PtrSafe  GetSystemDefaultLangID Lib "kernel32" () As Long
Private Declare PtrSafe  VerLanguageName Lib "kernel32" Alias "VerLanguageNameA" (ByVal wLang As Long, ByVal szLang As String, ByVal nSize As Long) As Long
#Else
Private Declare Function GetSystemDefaultLangID Lib "kernel32" () As Long
Private Declare Function VerLanguageName Lib "kernel32" Alias "VerLanguageNameA" (ByVal wLang As Long, ByVal szLang As String, ByVal nSize As Long) As Long
#End If
Function Langue_Systeme$()
    Dim Ident$, Nom_Langue$
    Ident = "&H" & Right(Hex(GetSystemDefaultLangID()), 3)
    Nom_Langue = String(255, 0)
    VerLanguageName CLng(Ident), Nom_Langue, Len(Nom_Langue)
    Nom_Langue = Left$(Nom_Langue, InStr(1, Nom_Langue, Chr$(0)) - 1)
    Langue_Systeme = Nom_Langue
End Function

Sub test()
MsgBox Langue_Systeme$
End Sub
 

Bernard_XLD

XLDnaute Barbatruc
Membre du Staff
Re, Patrick

toi qui est un spécialiste des macrocommandes Excel4, il n'y a pas moyen de faire un appel aux api qui soit compatible toutes versions ?

Cordialement, @+
 

Bernard_XLD

XLDnaute Barbatruc
Membre du Staff
Re, Patrick

#If VBA7 Then Private Declare PtrSafe GetSystemDefaultLangID Lib "kernel32" () As Long Private Declare PtrSafe VerLanguageName Lib "kernel32" Alias "VerLanguageNameA" (ByVal wLang As Long, ByVal szLang As String, ByVal nSize As Long) As Long #Else Private Declare Function GetSystemDefaultLangID Lib "kernel32" () As Long Private Declare Function VerLanguageName Lib "kernel32" Alias "VerLanguageNameA" (ByVal wLang As Long, ByVal szLang As String, ByVal nSize As Long) As Long #End If
en fait ton code du post 6 ne fonctionnait pas chez moi car il y a une erreur dans les déclarations, il manque le mot clé Function dans les deux premières, une fois rectifié, ça fonctionne bien donc le code est bien compatible.
il n'y a pas moyen de faire un appel aux api qui soit compatible toutes versions ?
Comme les deux déclarations passaient en rouge, j'ai d'abord pensé à une erreur de compatibilité.

@Magic_Doctor , tu confirmes que ça fonctionne bien aussi, tel quel, sous Excel 2007 ?

Cordialement, @+
VB:
#If VBA7 Then
    Private Declare PtrSafe Function GetSystemDefaultLangID Lib "kernel32" () As Long
    Private Declare PtrSafe Function VerLanguageName Lib "kernel32" Alias "VerLanguageNameA" (ByVal wLang As Long, ByVal szLang As String, ByVal nSize As Long) As Long
#Else
    Private Declare Function GetSystemDefaultLangID Lib "kernel32" () As Long
    Private Declare Function VerLanguageName Lib "kernel32" Alias "VerLanguageNameA" (ByVal wLang As Long, ByVal szLang As String, ByVal nSize As Long) As Long
#End If

Function Langue_Systeme$()
    Dim Ident$, Nom_Langue$
    Ident = "&H" & Right(Hex(GetSystemDefaultLangID()), 3)
    Nom_Langue = String(255, 0)
    VerLanguageName CLng(Ident), Nom_Langue, Len(Nom_Langue)
    Nom_Langue = Left$(Nom_Langue, InStr(1, Nom_Langue, Chr$(0)) - 1)
    Langue_Systeme = Nom_Langue
End Function

Sub test()
MsgBox Langue_Systeme$
End Sub
 

patricktoulon

XLDnaute Barbatruc
et j'oubliais
pour info
CodeLangueSysteme = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
donne la langue dans la quelle est installée office et non celle de windows

pour info

Sub test2()
x = Application.International(xlCountrySetting)'donne le code excel du langage windows
Select Case x
Case 33: pays = "french"
Case 1: pays = "US"
Case 44: pays = "spanich"
'etc...
End Select
MsgBox pays
End Sub
pour info aussi comme ça c'est clair pour tout le monde
 
Dernière édition:

Magic_Doctor

XLDnaute Barbatruc
Bonjour
pour les version 32 (2003,2007) il suffit d'adapter les api
VB:
#If VBA7 Then
Private Declare PtrSafe  GetSystemDefaultLangID Lib "kernel32" () As Long
Private Declare PtrSafe  VerLanguageName Lib "kernel32" Alias "VerLanguageNameA" (ByVal wLang As Long, ByVal szLang As String, ByVal nSize As Long) As Long
#Else
Private Declare Function GetSystemDefaultLangID Lib "kernel32" () As Long
Private Declare Function VerLanguageName Lib "kernel32" Alias "VerLanguageNameA" (ByVal wLang As Long, ByVal szLang As String, ByVal nSize As Long) As Long
#End If
Function Langue_Systeme$()
    Dim Ident$, Nom_Langue$
    Ident = "&H" & Right(Hex(GetSystemDefaultLangID()), 3)
    Nom_Langue = String(255, 0)
    VerLanguageName CLng(Ident), Nom_Langue, Len(Nom_Langue)
    Nom_Langue = Left$(Nom_Langue, InStr(1, Nom_Langue, Chr$(0)) - 1)
    Langue_Systeme = Nom_Langue
End Function

Sub test()
MsgBox Langue_Systeme$
End Sub
Re,

Ça marche !
Il ne reste plus qu'à virer la fonction que j'avais proposée.
 

Discussions similaires

Statistiques des forums

Discussions
314 710
Messages
2 112 115
Membres
111 428
dernier inscrit
Andrya