返回首页
当前位置: 主页 > Excel教程 > Excel VBA教程 >

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

时间:2012-06-17 02:43来源:Office教程学习网 www.office68.com编辑:麦田守望者

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

------分隔线----------------------------
标签(Tag):excel excel2007 excel2010 excel2003 excel技巧 excel教程 excel实例教程 excel2010技巧
------分隔线----------------------------
推荐内容
猜你感兴趣