What key is being pressed when running a macro?

G

Guest

Is there a way to detect what key is being pressed when running a macro? I
am familiar with the Keydown method, but I am using a button from the forms
toolbar not an active X button (so I assume that this procedure won't work).
So, is there a way to detect whether the shift key is being pressed when I
press a button to run a macro? I realize that I could switch the button for
an active X command button, but I would like to learn the answer regardless.
Thanks!
 
G

Guest

Declare Function GetKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As
Integer
Public Const VK_SHIFT As Integer = &H10

Sub MyMacro()
If GetKeyState(VK_SHIFT) < 0 Then
ActiveCell = "Shift key pressed"
Else
ActiveCell = "Shift key NOT pressed"
End If
End Sub

Regards,
Greg
 
G

Guest

Thanks Greg. That works perfectly.

Greg Wilson said:
Declare Function GetKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As
Integer
Public Const VK_SHIFT As Integer = &H10

Sub MyMacro()
If GetKeyState(VK_SHIFT) < 0 Then
ActiveCell = "Shift key pressed"
Else
ActiveCell = "Shift key NOT pressed"
End If
End Sub

Regards,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top