Aquí va el plan "B"...
Código para el UserForm:
Private Sub UserForm_Initialize()
Call HookForm(Me)
End Sub
Código para un módulo:
Option Explicit
Option Private Module
'//By JuanC - 26 de Julio 2007
Private Declare Function apiSetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function apiSendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function apiCallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function apiFindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function apiRegisterHotKey Lib "user32" Alias "RegisterHotKey" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function apiUnregisterHotKey Lib "user32" Alias "UnregisterHotKey" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function apiGlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Long
Private Declare Function apiGlobalDeleteAtom Lib "kernel32" Alias "GlobalDeleteAtom" (ByVal nAtom As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private Const WM_HOTKEY = &H312
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060
Private Const VK_ESCAPE = &H1B
Private m_OldWndProc As Long
Private m_hWnd As Long
Private m_idHotKeyEsc As Long
Private Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_HOTKEY
Select Case wParam
Case m_idHotKeyEsc
Call apiUnregisterHotKey(hWnd, m_idHotKeyEsc)
Call apiGlobalDeleteAtom(m_idHotKeyEsc)
Call apiSendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0)
End Select
End Select
WindowProc = apiCallWindowProc(m_OldWndProc, hWnd, Msg, wParam, lParam)
End Function
Public Sub HookForm(ByVal frm As Object)
m_hWnd = 0
If Val(Application.Version) < 9 Then
m_hWnd = apiFindWindow("ThunderXFrame", frm.Caption)
Else
m_hWnd = apiFindWindow("ThunderDFrame", frm.Caption)
End If
If m_hWnd = 0 Then Exit Sub
m_idHotKeyEsc = apiGlobalAddAtom(CStr(Date & Time))
Call apiRegisterHotKey(m_hWnd, m_idHotKeyEsc, 0, VK_ESCAPE)
m_OldWndProc = apiSetWindowLong(m_hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Saludos desde Baires, JuanC