hello
I'm working with XLX with Panther and i would like with VBA disable
all the shortcuts but after my work i would like enabe the shortcuts.
You could disable individual keyboard shortcuts with
Application.OnKey "*p",""
to reset them:
Application.OnKey "*p"
If you have a lot that you wish to disable, you might consider something
like:
Public Sub DisableKeys()
Dim vKSArray As Variant
Dim i As Long
vKSArray = Array("*c", "*v", "*s", "*p")
For i = 0 To UBound(vKSArray)
Application.OnKey vKSArray(i), ""
Next i
End Sub
Public Sub EnableKeys()
Dim vKSArray As Variant
Dim i As Long
vKSArray = Array("*c", "*v", "*s", "*p")
For i = 0 To UBound(vKSArray)
Application.OnKey vKSArray(i)
Next i
End Sub
Now I've got 2 VERY STRONG recommendations (please don't be offended if
you've already thought about them - too many XL coders haven't):
1) This is a technique that would p*ss me off royally, especially if you
disable keyboard shortcuts that I like to use. Often there's another way
to accomplish what you're trying to do (which isn't clear from your
post). So I recommend you think about whether your users will be happy
with your hijacking their computer.
2) It's not uncommon to have more than just your workbook open. If I was
working on a model, opened your workbook, switched back to my model and
found I couldn't use my keyboard shortcuts, that would be the last time
I'd ever use your workbook! One way to be a good XL citizen is to use
the Workbook_Activate and Workbook_Deactivate events to disable your
customizations when switching to another workbook. For instance, you
could put this in your ThisWorkbook code module:
Private Sub Workbook_Activate()
DisableKeys
End Sub
Private Sub Workbook_Deactivate()
EnableKeys
End Sub