ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Disabeling key (https://www.excelbanter.com/excel-programming/350785-disabeling-key.html)

Brian Matlack[_50_]

Disabeling key
 

Hi!
I would like to disable the DELETE key whenever a particular sheet is
selected and then reenable it whenever any other sheet is selected.
I have this code in the VBA sheet I want it disabled in.

[start code]
Private Sub disable1()
' This macro disables the Delete key
Application.OnKey "{DELETE}", ""
End Sub
[end code]

If I use this code on all the other sheets it should reenable the key.

[start code]
Private Sub disable2()
' This macro enables the Delete key
Application.OnKey "{DELETE}"
End Sub
[end code]

It does'nt work. What am I doing wrong?
I would be greatfull for any help. Thanks!!


--
Brian Matlack
------------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
View this thread: http://www.excelforum.com/showthread...hreadid=502533


GB

Disabeling key
 
You need to place your delete key enable/disable in the activate code for
each of the sheets. Or to make it simpler, place the disable code in the
worksheet_activate, and the enable code in the worksheet_deactivate. Would
recommend also verifying that if the delete is disabled, and another workbook
is opened at the same time, that the delete key works as expected there.
Also, that when closing the workbook that the delete key is restored to
normal.



"Brian Matlack" wrote:


Hi!
I would like to disable the DELETE key whenever a particular sheet is
selected and then reenable it whenever any other sheet is selected.
I have this code in the VBA sheet I want it disabled in.

[start code]
Private Sub disable1()
' This macro disables the Delete key
Application.OnKey "{DELETE}", ""
End Sub
[end code]

If I use this code on all the other sheets it should reenable the key.

[start code]
Private Sub disable2()
' This macro enables the Delete key
Application.OnKey "{DELETE}"
End Sub
[end code]

It does'nt work. What am I doing wrong?
I would be greatfull for any help. Thanks!!


--
Brian Matlack
------------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
View this thread: http://www.excelforum.com/showthread...hreadid=502533



Brian Matlack[_51_]

Disabeling key
 

Thanks GB!! Works Great!!
I am still (and may always be) a rookie!


--
Brian Matlack
------------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
View this thread: http://www.excelforum.com/showthread...hreadid=502533


GB

Disabeling key
 
Everyone always is... :) Ego's set aside. :)

Good, remember we work today, but we should also think about tomorrow.
(i.e., forward effects of current work or where are we headed, and what does
it take to get there.)

"Brian Matlack" wrote:


Thanks GB!! Works Great!!
I am still (and may always be) a rookie!


--
Brian Matlack
------------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
View this thread: http://www.excelforum.com/showthread...hreadid=502533




All times are GMT +1. The time now is 12:36 AM.

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