ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What key is being pressed when running a macro? (https://www.excelbanter.com/excel-programming/369660-what-key-being-pressed-when-running-macro.html)

Noah

What key is being pressed when running a macro?
 
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!

Greg Wilson

What key is being pressed when running a macro?
 
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

"Noah" wrote:

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!



All times are GMT +1. The time now is 06:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com