En ocasiones necesitamos tener cierto control sobre nuestro libro de Excel y únicamente permitir la selección de controles de formulario a través del ratón.
Les comparto una forma de bloquear el teclado con API’s (Application Programming Interface), únicamente tienen que pegar el código en un módulo estandar y ejecutar el código BloquearTeclado para bloquear y DesbloquearTeclado para desbloquear.
Option Explicit Private Declare Function SetWindowsHookEx _ Lib "user32.dll" Alias "SetWindowsHookExA" ( _ ByVal idHook As Long, _ ByVal lpfn As Long, _ ByVal hmod As Long, _ ByVal dwThreadId As Long) As Long Private Declare Function UnhookWindowsHookEx Lib "user32" ( _ ByVal hHook As Long) As Long Private Const WH_KEYBOARD_LL = 13& Private m_Hook As Long Public Function LowLevelKeyboardProc( _ ByVal nCode As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long LowLevelKeyboardProc = 1 End Function Sub Hook() m_Hook = SetWindowsHookEx( _ WH_KEYBOARD_LL, _ AddressOf LowLevelKeyboardProc, _ Application.Hinstance, 0&) If m_Hook = 0 Then _ MsgBox "Fallo enganchando", vbExclamation End Sub Sub UnHook() Call UnhookWindowsHookEx(m_Hook) End Sub Private Sub Bloquear() Call Hook End Sub Private Sub Desbloquear(Cancel As Integer) Call UnHook End Sub