Consulting

Results 1 to 8 of 8

Thread: Disable Copy Paste

  1. #1
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    4
    Location

    Disable Copy Paste

    I've used the code located in article 373 (/kb/getarticle.php?kb_id=373) but it does not disable the "Clipboard" menu at the top of Excel 2007. All other copy/cut/paste features are in fact disabled with this macro, except for the toolbar features ("Home" tab, "Clipboard" section). Is there a way to disable this workaround?

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Perhaps something like this in a sheet's code module. Or in the ThisWorkbook SheetSelectionChange event.
    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
        Dim xDat As New DataObject
        Application.CutCopyMode = False
        With xDat
            .SetText "Not Allowed"
            .PutInClipboard
        End With
    End Sub

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    You can try the attached!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    4
    Location
    I've tried both of these solutions, and neither limit the cut/copy/paste feature from the toolbar at the top of Excel.

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Mine definately does!, which version of Excel are you using? have you got macro's enabled?

    I suspect that macro's are disabled, the fact that you can write code, view it or change it is not an indicator that they are enabled!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    4
    Location
    Thanks for the follow-up, Simon. I've definitely enabled macros, and the code disabled the right click drop down options for copy, cut and paste as well as the keyboard shortcuts for this as well. In the file you attached, however, I am still able to use the menu to copy and paste from cell a1 to cell b1, for example.

  7. #7
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Well all i can suggest is that you go to the Thisworkbook module run the workbooks open event, or activate a different worksheet and then try, because in the example i gave all copy/pastes have been disabled, i downloaded my example and the copy cut etc. is greyed out when you try to use it!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  8. #8
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    4
    Location
    I'm running 2007 and I manually ran the workbooks open event and took a look at the code and stepped through the process. It perpetually loops in the red part of the following code:

    [vba]Sub EnableMenuItem(ctlId As Integer, 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 ' Begin loop
    Set cBarCtrl = cBar.FindControl(ID:=ctlId, recursive:=True)
    If Not cBarCtrl Is Nothing Then cBarCtrl.Enabled = Enabled
    End If
    Next
    ' End loop
    End Sub[/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •