2.双击要禁止delete的sheet,例如sheet1
3.在右边的编辑区的最上面加入下面的函数声明
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
对该sheet追加change事件
Private Sub Worksheet_Change(ByVal Target As Range) Dim keys(0 To 255) As Byte GetKeyboardState keys(0) If keys(46) > 127 Then Application.EnableEvents = False Application.Undo MsgBox "这个sheet不能使用delete键" Application.EnableEvents = True End If End Sub
因为Change好像没有Cancel参数,所以加入Application.EnableEvents = False Application.Undo意思就是撤消上一操作,即改回去将删除的东西给改回去。