ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Disable Cntrl_C and Cntrl_V in VBA (https://www.excelbanter.com/excel-programming/309703-disable-cntrl_c-cntrl_v-vba.html)

Celtic_Avenger[_28_]

Disable Cntrl_C and Cntrl_V in VBA
 
I have been very kindly given the code to disable the right mouse butto
in a spreadsheet I am creating.

I have found that if I create a new macro in this workbook and assig
Ctrl_C to it, but then leave the macro blank, this does what I want
but If I open another workbook at the same time, Ctrl_C remain
disabled until I close the workbook that contains the blank macro.

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

Is this possible?

thanks

Celtic_Avenger
:confused: :cool: :confused: :cool: :confused

--
Message posted from http://www.ExcelForum.com


Stephen Bullen[_3_]

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




All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com