View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Disable Shortcuts

Actually it seems the Dummy macro is not required at all. Try this -

Sub SetShortcuts(bDisable As Boolean)
Dim i As Long, j As Long
Dim sKey As String
Dim vArr

vArr = Array("^", "+^") ' (ctrl, shift-ctrl)

For i = Asc("a") To Asc("z") ' 97 to 122
For j = 0 To 1
sKey = vArr(j) & Chr(i)

If bDisable Then
Application.OnKey sKey, ""
Else
Application.OnKey sKey
End If
Next
Next

End Sub

Regards,
Peter T


"Peter T" <peter_t@discussions wrote in message
...
Sub test()

SetShortcuts True ' disable shortcuts

' SetShortcuts False ' reset shortcuts

End Sub

Sub DummyMacro()
' no code in the macro
MsgBox "DummyMacro" ' just to test
End Sub

Sub SetShortcuts(bDisable As Boolean)
Dim i As Long, j As Long
Dim sMacro As String, sKey As String
Dim vArr

vArr = Array("^", "+^") ' (ctrl, shift-ctrl)
sMacro = "'" & ThisWorkbook.Name & "'!DummyMacro"

For i = Asc("a") To Asc("z") ' 97 to 122
For j = 0 To 1
sKey = vArr(j) & Chr(i)

If bDisable Then
Application.OnKey sKey, sMacro
Else
Application.OnKey sKey
End If
Next
Next

End Sub

Assigs ctrl & ctrl+shift a to z to the dummy macro. Adapt if you also want
to include
numbers and the F keys. See OnKey in help

Regards,
Peter T

"Roger" wrote in message
...
Peter - just the excel ones like ctrl-c copy


--
Roger


"Peter T" wrote:

Do you mean shortcuts assigned to macros or all shortcuts, like ctrl-c

copy,
or both..

Regards,
Peter T


"Roger" wrote in message
...
Is ther a way to disable all keyborad shortcuts in a "For Each" or
similiar


--
Roger