I need to unarchive the Print Screen function of a file.
The file I posted was the same one I found on the internet.
This code works on this file, but when trying to run in the 2013 version it gets in error.
Would anyone know how to solve it?
Thisworkbook:
Modules:
The file I posted was the same one I found on the internet.
This code works on this file, but when trying to run in the 2013 version it gets in error.
Would anyone know how to solve it?
Thisworkbook:
Code:
[/COLOR]Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
UnsetKeyboardHook
End Sub
Private Sub Workbook_Deactivate()
UnsetKeyboardHook
End Sub
Private Sub Workbook_Open()
SetKeyboardHook
End Sub
[COLOR=#333333]
Modules:
Code:
[/COLOR]Option Explicit
Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Const WH_KEYBOARD_LL = &HD
Private Const WM_KEYDOWN = &H100
Private Const WM_SYSKEYDOWN = &H104
Private Const HC_ACTION = 0
Private Const VK_PRINTSCREEN = &H2C
Public Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Private hHook As Long
Public Function SetKeyboardHook() As Long
If hHook = 0 Then
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, Application.Hinstance, 0)
SetKeyboardHook = hHook
End If
End Function
Public Sub UnsetKeyboardHook()
Call UnhookWindowsHookEx(hHook)
hHook = 0
End Sub
Private Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lpllkHookStruct As KBDLLHOOKSTRUCT
If nCode = HC_ACTION Then
Call CopyMemory(lpllkHookStruct, ByVal lParam, Len(lpllkHookStruct))
If lpllkHookStruct.vkCode = VK_PRINTSCREEN Then
LowLevelKeyboardProc = True
Else
LowLevelKeyboardProc = CallNextHookEx(hHook, nCode, wParam, lParam)
End If
Else
LowLevelKeyboardProc = CallNextHookEx(hHook, nCode, wParam, lParam)
End If
End Function
[COLOR=#333333]