Enable copying function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear experts,

I locate a code to disable the copy and paste function in web for one of my
workbooks in Excel. After adding the code to the workbook module, it not only
disabled the copy and paste function of that workbook, it disabled all other
workbooks as well (including new workbooks). The disable including icons on
standard toolbar and right click menu. The function under Edit menu is still
OK. Even I deleted the code from the window module, I still cannot enable the
copy and paste function back. Any solution I can enable back the copy and
paste function except only that workbook. Please help and advise how. I list
the code below for your reference.

Thanks a million.

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
 
As the code is written by an Excel MVP stating the code function,
unfortunately, it did not state any risk of using it. Since I'm just a newbie
of VBA, how can I know the risk? I will not make any comments to your word
"stupid". Thanks anyway.
 
Hey, I am not trying to insult you, I said I myself may be stupid for asking
this question. What I want to know is whether you actually ran the routine
to enable cut and paste again. The code example you gave, shows the routine,
but it does not show code that actually calls this routine. I ask again.
Have you actually tried to run this sub routine? If not, running it should
return functionality to what it was before.

In Excel, if you run a macro which changes normal behaviour, you have to run
a reverse operation, otherwise you sit with what you have now. In other
words, while running such a routine may appear not to have a global effect on
Excel, it actually does! Only by running the reverse routine, before exiting
the affected file, will it return functionality to normal for other workbooks.

Being a newbie is no disgrace! It actually displays courage to tackle the
unknown, my friend. It also lets one step into traps like this, and without
assistance you will not get out of the trap. Can we try again? Awfully
sorry if I offended you. It was definitely not the intention.
 
Dear Kassie,

Totally understood. Thanks for your reminding to ask me to run the "Enable"
code. The copy and paste functions are now restored. Actually, I'm too stupid
to overlook this step. Thanks for your time and kindness. Cheers.

Freshman
 
Back
Top