PDA

View Full Version : Solved: Disable Space Bar & Delete button



khalid79m
01-08-2009, 03:58 AM
How can I disable the space bar button and delete button ?

is there an easy way to identify keyboard keys in vba ? to they have numbers assigned to them or soemthing ?

khalid79m
01-08-2009, 04:04 AM
Where can I get a Menu Item list ?

jfournier
01-08-2009, 08:20 AM
You can intercept keys in Excel VBA by using the OnKey method in the Excel application object. Basically you tell Excel to execute a VBA sub when the user hits a button instead of whatever Excel usually does. To set it up you would have to put in the OnKey calls on the workbook_open event in the ThisWorkbook module. It would be something like this:


Private Sub Workbook_Open()
Application.OnKey "{DELETE}", "InterceptKey"
Application.OnKey " ", "InterceptKey"
Application.OnKey "{BACKSPACE}", "InterceptKey"

End Sub

where you have a public InterceptKey sub in a standard module. This will get called when you hit delete, backspace, or the spacebar. In the workbook_close event you'd have to undo this, passing a blank string rather than "InterceptKey"

Hope that helps...

Jon

khalid79m
01-08-2009, 09:31 AM
Do you know the menuitem number for clearcontents ?

Call EnableMenuItem(755, Allow) ' pastespecial

khalid79m
02-05-2009, 08:37 AM
Cheers mate thanks