View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Stephen Bullen[_3_] Stephen Bullen[_3_] is offline
external usenet poster
 
Posts: 74
Default Disable Cntrl_C and Cntrl_V in VBA

Hi Celtic_Avenger,

I would like to know if there is a way to disable the Ctrl_C and Ctrl_V
shortcuts in this workbook only, but allow them to work in other open
workbooks.


Sure. You need to hook the workbook's events and disable them when one
of the workbook's windows is activated and enable them when one of the
workbook's windows is deactivated. I guess you also need to handle
Shift+Insert and Ctrl+Insert as well. Put the following in the
ThisWorkbook module:

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
'Disable when switching to us
Application.OnKey "^C", ""
Application.OnKey "^c", ""
Application.OnKey "^{INSERT}", ""

Application.OnKey "^V", ""
Application.OnKey "^v", ""
Application.OnKey "+{INSERT}", ""
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
'Enable when switching away
Application.OnKey "^C"
Application.OnKey "^c"
Application.OnKey "^{INSERT}"

Application.OnKey "^V"
Application.OnKey "^v"
Application.OnKey "+{INSERT}"
End Sub


Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.ie