Disable Cut Copy Paste

Gajendran Yadhav

Board Regular
Joined
Sep 8, 2023
Messages
51
Office Version
  1. 2010
  2. 2007
Platform
  1. 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:
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..??
1722842768342.png


I want this option to be disabled as well... any help is deeply appreciated.
TIA
Gajendran Yadhav
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You'll have to add ribbonX code to your file that disables the paste drop-down on the home tab:
XML:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <commands>
        <command idMso="PasteMenu" enabled="false"/>
    </commands>
</customUI>
 
Upvote 0

Forum statistics

Threads
1,224,746
Messages
6,180,705
Members
452,994
Latest member
Janick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top