Application.OnKey "s"

AlbyDangles

New Member
Joined
Dec 14, 2013
Messages
6
I am running a macro by pressing the "s" key if the active cell is in column 3 and the row height is 31.5. That part is working OK.

My problem is I have to press the "s" key twice when a cell that is not in column 3 and the row height is 31.5 is selected.



Private Sub XL_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.OnKey "s", "Process_S_KeyEvent"
End Sub






Private Sub Process_S_KeyEvent()


If ActiveCell.Column = 3 And ActiveCell.RowHeight = 31.5 Then
MsgBox "Hello"

Exit Sub
Else
Application.OnKey "s" 'I think the problem is here
End If


End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
see if this works...

Code:
Private Sub Process_S_KeyEvent()
    If ActiveCell.Column = 3 And ActiveCell.RowHeight = 31.5 Then
        MsgBox "Hello"
    Else
        MsgBox "not correct height or column"
    End If
End Sub
 
Upvote 0
Dont forget to assign it, try this codes

jiuk

Code:
Sub JACKS_Apps_KEY_MY_RUN_IT()

'Written by Jack in the UK : For http://www.mrexcel.com/
'// Feed - /forum/excel-questions/602726-application-onkey-not-working.html
'// 30 Jan  2014

'// jiuk to "RUN IT"
Application.OnKey "^s", "Jacks TEST"

'// jiuk - NOTE .....
'// jiuk - Jacks test is a seperate macro that is called by "s"

End Sub
Code:
Sub Jacks_TURN_IT_OFF()
    Application.OnKey "^e"
End Sub
Code:
Sub Jacks_TEST_IT_WORKS()
MsgBox "Jack says it  A works" & _
vbCrLf & _
"Application Key S activated"

End Sub
 
Upvote 0
Thanks for your reply diddi.
I need to get the "s" key to return to normal when my if statement is false.


Private Sub Process_S_KeyEvent() If ActiveCell.Column = 3 And ActiveCell.RowHeight = 31.5 Then MsgBox "Hello" Else make the "s" key work as normal End IfEnd Sub</pre>
 
Upvote 0
To return a key combination to the default,

Code:
application.onkey, "keycombination"
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top