Thread: Keypress
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default Keypress

You beat me by 10 mins. Thought I'd posted to broogle. I wrote mine, tested
it, opened broggle's post, noticed no one had replied yet. So I went back and
copied my code (three different code modules). Thought I clicked on broggle's
post when I replied. Got to quite this late night posting.

"Bob Phillips" wrote:

Same as mine <g

"Greg Wilson" wrote in message
...
This is my suggestion:

'Paste to the Worksheet module
Private Sub Worksheet_Change(ByVal Target As Range)
If DisableStatus Then Exit Sub
'Your code in place of MsgBox
MsgBox "Test"
End Sub

'Paste to ThisWorkbook module
Private Sub Workbook_Activate()
With Application
.OnKey "E", "DisableWC"
.OnKey "R", "EnableWC"
End With
End Sub

Private Sub Workbook_Deactivate()
With Application
.OnKey "E"
.OnKey "R"
End With
End Sub

'Paste to a standard module
Public DisableStatus As Boolean

Sub DisableWC()
MsgBox "Worksheet_Change event disabled"
DisableStatus = True
End Sub

Sub EnableWC()
MsgBox "Worksheet_Change event enabled"
DisableStatus = False
End Sub

Regards,
Greg


"broogle" wrote:

Please help,

I have a worksheet_change event, I want to disable this event if key
"E" is pressed and enable it again if key "R" is pressed. Is it
possible? How can I do that?

Thanks