EXCEL中VBA如何禁止与启用快捷键

来源:转载

Private Sub Workbook_Open()

With Application

'禁止自动填充

.CellDragAndDrop = False

'屏蔽常用工具栏剪切、复制、粘贴

.CommandBars(3).Controls("剪切(&T)").Enabled = False

.CommandBars(3).Controls("复制(&C)").Enabled = False

.CommandBars(3).Controls("粘贴(&P)").Enabled = False

'屏蔽单元格右键菜单中的剪切、复制、粘贴命令

.CommandBars("Cell").Controls("剪切(&T)").Enabled = False

.CommandBars("Cell").Controls("复制(&C)").Enabled = False

.CommandBars("Cell").Controls("粘贴(&P)").Enabled = False

'屏蔽列右键菜单中的剪切、复制、粘贴命令

.CommandBars("Column").Controls("剪切(&T)").Enabled = False

.CommandBars("Column").Controls("复制(&C)").Enabled = False

.CommandBars("Column").Controls("粘贴(&P)").Enabled = False

'屏蔽行右键菜单中的剪切、复制、粘贴命令

.CommandBars("Row").Controls("剪切(&T)").Enabled = False

.CommandBars("Row").Controls("复制(&C)").Enabled = False

.CommandBars("Row").Controls("粘贴(&P)").Enabled = False

'屏蔽编辑菜单中的剪切、复制、粘贴命令

.CommandBars(1).Controls("编辑(&E)").Controls("剪切(&T)").Enabled = False

.CommandBars(1).Controls("编辑(&E)").Controls("复制(&C)").Enabled = False

.CommandBars(1).Controls("编辑(&E)").Controls("粘贴(&P)").Enabled = False

'屏蔽键盘剪切、复制、粘贴键

.OnKey "^x", ""

.OnKey "^c", ""

.OnKey "^v", ""

End With

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)

With Application

'恢复自动填充

.CellDragAndDrop = True

'恢复常用工具栏剪切、复制、粘贴

.CommandBars(3).Controls("剪切(&T)").Enabled = True

.CommandBars(3).Controls("复制(&C)").Enabled = True

.CommandBars(3).Controls("粘贴(&P)").Enabled = True

'恢复单元格右键菜单中的剪切、复制、粘贴命令

.CommandBars("Cell").Controls("剪切(&T)").Enabled = True

.CommandBars("Cell").Controls("复制(&C)").Enabled = True

.CommandBars("Cell").Controls("粘贴(&P)").Enabled = True

'恢复列右键菜单中的剪切、复制、粘贴命令

.CommandBars("Column").Controls("剪切(&T)").Enabled = True

.CommandBars("Column").Controls("复制(&C)").Enabled = True

.CommandBars("Column").Controls("粘贴(&P)").Enabled = True

'恢复行右键菜单中的剪切、复制、粘贴命令

.CommandBars("Row").Controls("剪切(&T)").Enabled = True

.CommandBars("Row").Controls("复制(&C)").Enabled = True

.CommandBars("Row").Controls("粘贴(&P)").Enabled = True

'恢复编辑菜单中的剪切、复制、粘贴命令

.CommandBars(1).Controls("编辑(&E)").Controls("剪切(&T)").Enabled = True

.CommandBars(1).Controls("编辑(&E)").Controls("复制(&C)").Enabled = True

.CommandBars(1).Controls("编辑(&E)").Controls("粘贴(&P)").Enabled = True

'恢复键盘剪切、复制、粘贴键

.OnKey "^x"

.OnKey "^c"

.OnKey "^v"

End With

End Sub

分享给朋友:
您可能感兴趣的文章:
随机阅读: