禁用键或组合键
Disable key or key combination
如何禁用组合键或字符 office 2010。
我尝试了下面的代码,但没有用。
Sub Disable_Keys()
Dim KeysArray As Variant
Dim Key As Variant
KeysArray = Array("@", "!", "~", "%", "SHIFT+F12")
'Disable the StartKeyCombination key(s) with every key in the KeysArray
For Each Key In KeysArray
Application.OnKey Key, "myMsg"
Next Key
End Sub
Private Sub Workbook_Open()
'// Disable Accelerators keys in Excel 2007-2013
Dim Ctl As CommandBarControl
For Each Ctl In Application.CommandBars("&Legacy Keyboard Support").Controls
Ctl.Tag = Ctl.Caption
Ctl.Caption = Replace(Ctl.Caption, "&", "")
Next
Dim StartKeyCombination As Variant
Dim KeysArray As Variant
Dim Key As Variant
Dim I As Long
On Error Resume Next
'// Shift key = "+" (plus sign)
'// Ctrl key = "^" (caret)
'// Alt key = "%" (percent sign
'// We fill the array with this keys and the key combinations
'// Shift-Ctrl, Shift- Alt, Ctrl-Alt, Shift-Ctrl-Alt
For Each StartKeyCombination In Array("+", "^", "%", "+^", "+%", "^%", "+^%")
KeysArray = Array("{BS}", "{BREAK}", "{CAPSLOCK}", "{CLEAR}", "{DEL}", _
"{DOWN}", "{END}", "{ENTER}", "~", "{ESC}", "{HELP}", "{HOME}", _
"{INSERT}", "{LEFT}", "{NUMLOCK}", "{PGDN}", "{PGUP}", _
"{RETURN}", "{RIGHT}", "{SCROLLLOCK}", "{TAB}", "{UP}")
'// Disable the StartKeyCombination
For Each Key In KeysArray
Application.OnKey StartKeyCombination & Key, ""
Next Key
'// Disable the StartKeyCombination key(s) with every other key
For I = 0 To 255
Application.OnKey StartKeyCombination & Chr$(I), ""
Next I
'// Disable the F1 - F15 keys in combination with the Shift, Ctrl or Alt key
For I = 1 To 15
Application.OnKey StartKeyCombination & "{F" & I & "}", ""
Next I
Next StartKeyCombination
'// Disable the F1 - F15 keys
For I = 1 To 15
Application.OnKey "{F" & I & "}", ""
Next I
'// Disable the PGDN and PGUP keys
Application.OnKey "{PGDN}", ""
Application.OnKey "{PGUP}", ""
End Sub
参考以下链接
如何禁用组合键或字符 office 2010。
我尝试了下面的代码,但没有用。
Sub Disable_Keys()
Dim KeysArray As Variant
Dim Key As Variant
KeysArray = Array("@", "!", "~", "%", "SHIFT+F12")
'Disable the StartKeyCombination key(s) with every key in the KeysArray
For Each Key In KeysArray
Application.OnKey Key, "myMsg"
Next Key
End Sub
Private Sub Workbook_Open()
'// Disable Accelerators keys in Excel 2007-2013
Dim Ctl As CommandBarControl
For Each Ctl In Application.CommandBars("&Legacy Keyboard Support").Controls
Ctl.Tag = Ctl.Caption
Ctl.Caption = Replace(Ctl.Caption, "&", "")
Next
Dim StartKeyCombination As Variant
Dim KeysArray As Variant
Dim Key As Variant
Dim I As Long
On Error Resume Next
'// Shift key = "+" (plus sign)
'// Ctrl key = "^" (caret)
'// Alt key = "%" (percent sign
'// We fill the array with this keys and the key combinations
'// Shift-Ctrl, Shift- Alt, Ctrl-Alt, Shift-Ctrl-Alt
For Each StartKeyCombination In Array("+", "^", "%", "+^", "+%", "^%", "+^%")
KeysArray = Array("{BS}", "{BREAK}", "{CAPSLOCK}", "{CLEAR}", "{DEL}", _
"{DOWN}", "{END}", "{ENTER}", "~", "{ESC}", "{HELP}", "{HOME}", _
"{INSERT}", "{LEFT}", "{NUMLOCK}", "{PGDN}", "{PGUP}", _
"{RETURN}", "{RIGHT}", "{SCROLLLOCK}", "{TAB}", "{UP}")
'// Disable the StartKeyCombination
For Each Key In KeysArray
Application.OnKey StartKeyCombination & Key, ""
Next Key
'// Disable the StartKeyCombination key(s) with every other key
For I = 0 To 255
Application.OnKey StartKeyCombination & Chr$(I), ""
Next I
'// Disable the F1 - F15 keys in combination with the Shift, Ctrl or Alt key
For I = 1 To 15
Application.OnKey StartKeyCombination & "{F" & I & "}", ""
Next I
Next StartKeyCombination
'// Disable the F1 - F15 keys
For I = 1 To 15
Application.OnKey "{F" & I & "}", ""
Next I
'// Disable the PGDN and PGUP keys
Application.OnKey "{PGDN}", ""
Application.OnKey "{PGUP}", ""
End Sub
参考以下链接