0

I have a problem, I need a specific macro to run, whenever the cutcopymode is turned on, I mean I'll select some cells, and when I press Ctrl+c or Ctrl+x the macro test1 must run, I've tried this but nothing happens.

Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("A1:A10")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub

If Application.CutCopyMode = xlCopy Or Application.CutCopyMode = xlCut Then test1

End Sub
Community
  • 1
  • 1
Ygor Yansz
  • 176
  • 1
  • 4
  • 12

1 Answers1

0
Private Sub Workbook_Open()
Application.OnKey "^x", "YourSub"
Application.OnKey "^c", "YourSub"
End Sub

Put this on your ThisWorkbook module. It will call your macro named"YourSub".
Further info on e.g. http://www.mrexcel.com/archive/VBA/1981.html
You're welcome.

user3819867
  • 1,114
  • 1
  • 8
  • 18
  • It will call your macro named "YourSub" every time the Ctrl+X or Ctrl+C combos are used. For further annoying your client I recommend disabling the right click as well. – user3819867 Feb 27 '15 at 15:51
  • Get creative. As a start I'd recommend changing "YourSub" to "test1". If you've done that I recommend closing then opening the workbook. You may want to read my source, they have other instances calling these methods too. – user3819867 Mar 04 '15 at 07:55
  • i did changed yoursub for test1 and nothing happens, closed the workbook also, i understood what happens in your code it should be working, but it isent =/ – Ygor Yansz Mar 04 '15 at 13:31