Option Explicit
#If VBA7 Then
'https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getkeyboardlayout
Private Declare PtrSafe Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As LongPtr) As Long
'https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadkeyboardlayouta
Private Declare PtrSafe Function...
Option Explicit
#If VBA7 Then
'https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getkeyboardlayout
Private Declare PtrSafe Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As LongPtr) As Long
'https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadkeyboardlayouta
Private Declare PtrSafe Function LoadKeyboardLayout Lib "user32" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal flags As Long) As Long
#Else
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Private Declare Function LoadKeyboardLayout Lib "user32" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal flags As Long) As Long
#End If
Private Const KLF_ACTIVATE = &H1
'---------------------------------
'Retourne True si clavier français
'---------------------------------
Function ClavierEstFrançais() As Boolean
Dim KeyboardLayout As Long
KeyboardLayout = GetKeyboardLayout(0)
ClavierEstFrançais = True
'https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-input-locales-for-windows-language-packs
Select Case KeyboardLayout
Case &H484040C 'Alsatian - France
Case &H47E040C 'Breton - France
Case &H483040C 'Corsican - France
Case &H80C080C 'French - Belgium
Case &H40C040C 'French - France (AZERTY)
Case &H140C100C 'French - Luxembourg
Case &H180C040C 'French - Monaco
Case &H100C100C 'French - Switzerland
Case &H482040C 'Occitan - France
Case Else
ClavierEstFrançais = False
End Select
End Function
'----------------------------------
'Met le clavier en anglais (QWERTY)
'----------------------------------
Sub MetClavierEnAnglais()
Call LoadKeyboardLayout("00000409", KLF_ACTIVATE)
End Sub
'-----------------------------------
'Met le clavier en français (AZERTY)
'-----------------------------------
Sub MetClavierEnFrançais()
Call LoadKeyboardLayout("0000040C", KLF_ACTIVATE)
End Sub
'reprise du module clavier @Dudu2 sur exceldownload
'les api avec les macro4
'patricktoulon 04/08/2021
Option Explicit
'---------------------------------
'Retourne True si clavier français
'---------------------------------
Function ClavierEstFrançais() As Boolean
Dim KeyboardLayout As Long
KeyboardLayout = ExecuteExcel4Macro("CALL(""user32"",""GetKeyboardLayout"",""JJ""," & 0 & ")")
ClavierEstFrançais = True
'https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-input-locales-for-windows-language-packs
Select Case KeyboardLayout
Case &H484040C 'Alsatian - France
Case &H47E040C 'Breton - France
Case &H483040C 'Corsican - France
Case &H80C080C 'French - Belgium
Case &H40C040C 'French - France (AZERTY)
Case &H140C100C 'French - Luxembourg
Case &H180C040C 'French - Monaco
Case &H100C100C 'French - Switzerland
Case &H482040C 'Occitan - France
Case Else
ClavierEstFrançais = False
End Select
End Function
Sub test()
MsgBox ClavierEstFrançais
End Sub
'----------------------------------
'Met le clavier en anglais (QWERTY)
'----------------------------------
Sub MetClavierEnAnglais()
ExecuteExcel4Macro ("CALL(""user32"",""LoadKeyboardLayoutA"",""JCJ"",""00000409""," & &H1 & ")")
End Sub
'-----------------------------------
'Met le clavier en français (AZERTY)
'-----------------------------------
Sub MetClavierEnFrançais()
ExecuteExcel4Macro ("CALL(""user32"",""LoadKeyboardLayoutA"",""JCJ"",""0000040C""," & &H1 & ")")
End Sub