Gajendran Yadhav
Board Regular
- Joined
- Sep 8, 2023
- Messages
- 51
- Office Version
- 2010
- 2007
- Platform
- Windows
Dear All,
From our forum, I have learnt and have an Excel file where I have the following Code to disable and enable Cut - Copy & Paste functions.
And this works great.
Code:
but, is there any possibility that I can even prevent the Cut Copy & Paste function from the quick access tool in the Menu Bar as well..??
I want this option to be disabled as well... any help is deeply appreciated.
TIA
Gajendran Yadhav
From our forum, I have learnt and have an Excel file where I have the following Code to disable and enable Cut - Copy & Paste functions.
And this works great.
Code:
VBA Code:
Sub ToggleCutCopyAndPaste(Allow As Boolean)
'Activate/deactivate cut, copy, paste and pastespecial menu items
Call EnableMenuItem(21, Allow) ' cut
Call EnableMenuItem(19, Allow) ' copy
Call EnableMenuItem(22, Allow) ' paste
Call EnableMenuItem(755, Allow) ' pastespecial
'Activate/deactivate drag and drop ability
Application.CellDragAndDrop = Allow
'Activate/deactivate cut, copy, paste and pastespecial shortcut keys
With Application
Select Case Allow
Case Is = False
.OnKey "^c", "CutCopyPasteDisabled"
.OnKey "^v", "CutCopyPasteDisabled"
.OnKey "^x", "CutCopyPasteDisabled"
.OnKey "+{DEL}", "CutCopyPasteDisabled"
.OnKey "^{INSERT}", "CutCopyPasteDisabled"
Case Is = True
.OnKey "^c"
.OnKey "^v"
.OnKey "^x"
.OnKey "+{DEL}"
.OnKey "^{INSERT}"
End Select
End With
End Sub
Sub EnableMenuItem(ByVal ctlId As Integer, ByVal Enabled As Boolean)
' Activate/Deactivate specific menu item
Dim cBar As CommandBar
Dim cBarCtrl As CommandBarControl
For Each cBar In Application.CommandBars
If cBar.Name <> "Clipboard" Then
Set cBarCtrl = cBar.FindControl(ID:=ctlId, recursive:=True)
If Not cBarCtrl Is Nothing Then cBarCtrl.Enabled = Enabled
End If
Next
End Sub
Sub CutCopyPasteDisabled()
'Inform user that the functions have been disabled
MsgBox "Cut, Copy and Paste functions are disabled." & vbCrLf & _
"Enter the correct details!", vbExclamation, "Cut, Copy & Pste Disabled"
End Sub
Sub ToggleCutCopyButton()
Dim button As Shape
Dim currentState As String
Dim ws As Worksheet
' Set the worksheet
Set ws = ThisWorkbook.ActiveSheet ' Reference to the active sheet
' Unprotect the worksheet to change the name of the button
ws.Unprotect Password:="Unprotect"
' Get the button in cell XFD1
On Error Resume Next
Set button = ActiveSheet.Shapes("Button 62_Click")
On Error GoTo 0
If Not button Is Nothing Then
' Get the current state of the button label
currentState = button.TextFrame.Characters.Text
' Toggle the button label and call the corresponding subroutine
If currentState = "Enable" Then
button.TextFrame.Characters.Text = "Disable"
ToggleCutCopyAndPaste False ' Call ToggleCutCopyAndPaste with Allow parameter set to False
ElseIf currentState = "Disable" Then
button.TextFrame.Characters.Text = "Enable"
ToggleCutCopyAndPaste True ' Call ToggleCutCopyAndPaste with Allow parameter set to True
End If
End If
' Re-apply protection to the worksheet
ws.Protect Password:="Unprotect"
End Sub
but, is there any possibility that I can even prevent the Cut Copy & Paste function from the quick access tool in the Menu Bar as well..??
I want this option to be disabled as well... any help is deeply appreciated.
TIA
Gajendran Yadhav