View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
serkan serkan is offline
external usenet poster
 
Posts: 6
Default How to catch copy/paste & cut/paste ?

This one prevents people from all ways of cutting/copying
and pasting when your workbook is open. I think you can
derive what you need from that...

Run DisableCutAndPaste from a suitable event procedure
(e.g. Workbook_Open or Worksheet_Activate) and
EnableCutAndPaste
from another (e.g. Workbook_Close or
Worksheet_Deactivate).

Sub DisableCutAndPaste()
EnableControl 21, False ' cut
EnableControl 19, False ' copy
EnableControl 22, False ' paste
EnableControl 755, False ' pastespecial
Application.OnKey "^c", ""
Application.OnKey "^v", ""
Application.OnKey "+{DEL}", ""
Application.OnKey "+{INSERT}", ""
Application.CellDragAndDrop = False
End Sub

Sub EnableCutAndPaste()
EnableControl 21, True ' cut
EnableControl 19, True ' copy
EnableControl 22, True ' paste
EnableControl 755, True ' pastespecial
Application.OnKey "^c"
Application.OnKey "^v"
Application.OnKey "+{DEL}"
Application.OnKey "+{INSERT}"
Application.CellDragAndDrop = True
End Sub

Sub EnableControl(Id As Integer, Enabled As Boolean)
Dim CB As CommandBar
Dim C As CommandBarControl
For Each CB In Application.CommandBars
Set C = CB.FindControl(Id:=Id, recursive:=True)
If Not C Is Nothing Then C.Enabled = Enabled
Next
End Sub




-----Original Message-----
Hello everyone,

Quite new to VBA etc stuff (but not new to programming),

I am looking on
ways to catch a user's copy/cut + paste command from all

possible locations
(edit menu, keyboard shortcuts, other if any (are there

others?), then do
some modifications in the cells being copied/moved and

then paste to
wherever the user wanted to copy the stuff.

How do I do that ?

Many thanks in advance,
-arifi


.