![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
I want to use the IF procedure with a procedure for detecting whether the Control key (or Shift key) are being held down.
If they are I want to exit the procedure otherwise I want to continue with my code. How can I detect these keys please? |
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
One way you can do this is with API calls. How about this?
Code:
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
Const VK_SHIFT As Long = &H10
Const VK_CONTROL As Long = &H11
Sub YourProcedure()
If GetKeyState(VK_SHIFT) < 0 Then
MsgBox "Shift is being held"
End If
If GetKeyState(VK_CONTROL) < 0 Then
MsgBox "Control is being held"
End If
End Sub
D |
|
|
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks. This works well enough in context.
However, I am putting a file reference procedure (using the Bforeprint event) into the code. The problem is that I would like to save the procedure in a way that will enable any open workbook to use it. I want to save the beforeprint procedure (maybe in a class module) then save the workbook as an addin. I then want to be able to open any workbook and have the procedure apply to that workbook. Please please please can someone help me here! Thanks in advance. Jim |
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|