shadowplay
New Member
- Joined
- Aug 8, 2008
- Messages
- 13
Hi,
I have found the following code and it works a treat, however i would like to let my user copy and pase only in column E.
How can I adjust my code to make this possible?
*** In a standard module ***
'*** In the ThisWorkbook Module ***
I have found the following code and it works a treat, however i would like to let my user copy and pase only in column E.
How can I adjust my code to make this possible?
*** In a standard module ***
Code:
[COLOR=#0000ff]Option Explicit[/COLOR]
[COLOR=blue]Sub[/COLOR] ToggleCutCopyAndPaste(Allow [COLOR=blue]As[/COLOR] [COLOR=blue]Boolean[/COLOR])
[COLOR=darkgreen]'Activate/deactivate cut, copy, paste and pastespecial menu items[/COLOR]
[COLOR=blue]Call[/COLOR] EnableMenuItem(21, Allow) [COLOR=darkgreen]' cut[/COLOR]
[COLOR=blue]Call[/COLOR] EnableMenuItem(19, Allow) [COLOR=darkgreen]' copy[/COLOR]
[COLOR=blue]Call[/COLOR] EnableMenuItem(22, Allow) [COLOR=darkgreen]' paste[/COLOR]
[COLOR=blue]Call[/COLOR] EnableMenuItem(755, Allow) [COLOR=darkgreen]' pastespecial[/COLOR]
[COLOR=darkgreen]'Activate/deactivate drag and drop ability[/COLOR]
Application.CellDragAndDrop = Allow
[COLOR=darkgreen]'Activate/deactivate cut, copy, paste and pastespecial shortcut keys[/COLOR]
[COLOR=blue]With[/COLOR] Application
[COLOR=blue]Select Case[/COLOR] Allow
[COLOR=blue]Case[/COLOR] [COLOR=blue]Is[/COLOR] = [COLOR=blue]False[/COLOR]
.OnKey "^c", "CutCopyPasteDisabled"
.OnKey "^v", "CutCopyPasteDisabled"
.OnKey "^x", "CutCopyPasteDisabled"
.OnKey "+{DEL}", "CutCopyPasteDisabled"
.OnKey "^{INSERT}", "CutCopyPasteDisabled"
[COLOR=blue]Case[/COLOR] [COLOR=blue]Is[/COLOR] = [COLOR=blue]True[/COLOR]
.OnKey "^c"
.OnKey "^v"
.OnKey "^x"
.OnKey "+{DEL}"
.OnKey "^{INSERT}"
[COLOR=blue]End Select[/COLOR]
[COLOR=blue]End With[/COLOR]
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Sub[/COLOR] EnableMenuItem(ctlId [COLOR=blue]As[/COLOR] [COLOR=blue]Integer[/COLOR], Enabled [COLOR=blue]As[/COLOR] [COLOR=blue]Boolean[/COLOR])
[COLOR=darkgreen]'Activate/Deactivate specific menu item[/COLOR]
[COLOR=blue]Dim[/COLOR] cBar [COLOR=blue]As[/COLOR] CommandBar
[COLOR=blue]Dim[/COLOR] cBarCtrl [COLOR=blue]As[/COLOR] CommandBarControl
[COLOR=blue]For Each[/COLOR] cBar [COLOR=blue]In[/COLOR] Application.CommandBars
[COLOR=blue]If[/COLOR] cBar.Name <> "Clipboard" [COLOR=blue]Then[/COLOR]
[COLOR=blue]Set[/COLOR] cBarCtrl = cBar.FindControl(ID:=ctlId, recursive:=[COLOR=blue]True[/COLOR])
[COLOR=blue]If[/COLOR] [COLOR=blue]Not[/COLOR] cBarCtrl [COLOR=blue]Is[/COLOR] [COLOR=blue]Nothing[/COLOR] [COLOR=blue]Then[/COLOR] cBarCtrl.Enabled = Enabled
[COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=blue]Next[/COLOR]
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Sub[/COLOR] CutCopyPasteDisabled()
[COLOR=darkgreen]'Inform user that the functions have been disabled[/COLOR]
MsgBox "Sorry! Cutting, copying and pasting have been disabled in this workbook!"
[COLOR=blue]End Sub[/COLOR]
'*** In the ThisWorkbook Module ***
Code:
[COLOR=#0000ff]Option Explicit[/COLOR]
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Workbook_Activate()
[COLOR=blue]Call[/COLOR] ToggleCutCopyAndPaste([COLOR=blue]False[/COLOR])
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Workbook_BeforeClose(Cancel [COLOR=blue]As[/COLOR] [COLOR=blue]Boolean[/COLOR])
[COLOR=blue]Call[/COLOR] ToggleCutCopyAndPaste([COLOR=blue]True[/COLOR])
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Workbook_Deactivate()
[COLOR=blue]Call[/COLOR] ToggleCutCopyAndPaste([COLOR=blue]True[/COLOR])
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Workbook_Open()
[COLOR=blue]Call[/COLOR] ToggleCutCopyAndPaste([COLOR=blue]False[/COLOR])
[COLOR=blue]End Sub[/COLOR]