Problemstellung:
Nur für 32Bit Office Versionen
Wie kann ich mittels VBA die NumLock-Taste ein- bzw. ausschalten?
Code in ein neues öffentliches Modul kopieren:
Private Const VK_NUMLOCK = &H90 Private Const KEYEVENTF_EXTENDEDKEY = &H1 Private Const KEYEVENTF_KEYUP = &H2 Private Declare Sub keybd_event Lib "user32" _ (ByVal bVk As Byte, _ ByVal bScan As Byte, _ ByVal dwflags As Long, _ ByVal dwExtraInfo As Long) Private Declare Function GetKeyboardState Lib "user32" _ (pbKeyState As Byte) As Long Private Declare Function SetKeyboardState Lib "user32" _ (lppbKeyState As Byte) As Long Function SetNumLock(bStatus As Boolean) As Boolean Dim R As Variant Dim NumLockOn As Boolean Dim KeyTable(0 To 255) As Byte R = GetKeyboardState(KeyTable(0)) NumLockOn = (KeyTable(VK_NUMLOCK) <> 0) If (bStatus And Not NumLockOn) Or _ (Not bStatus And NumLockOn) Then keybd_event VK_NUMLOCK, _ &H45, _ KEYEVENTF_EXTENDEDKEY Or 0, 0 keybd_event VK_NUMLOCK, _ &H45, _ KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0 End If End Function
Aufruf:
SetNumLock False
würde die NumLock-Taste ausschalten
SetNumLock True
würde die NumLock-Taste einschalten
Ähnliche Artikel
Weiterlesen...