How to catch copy/paste & cut/paste ?

A

Arifi Koseoglu

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
 
S

Serkan

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
 
A

Arifi Koseoglu

Hi...

Again, thanks for the information below.

Now the question has taken a different form though.

As I understand, the mechanisms I implement similar to the ones below exist
in the workbook they are defined in only (as expected). But, what I need to
have is that the mechanism I implement will be available vor every excel
worksheet opened in the company. Is there a mechanism to create a "master"
or whatever excel file to be installed on everyones PC that will incorporate
my stuff into their excel sessions ?

TIA,A
-arifi
 
G

Guest

I think you'll have to put that file under XLStart folder
(Excel automatically loads the files there at start-up) on
every machine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top