Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable copying in a spreadsheet (97)

    Hi,

    How can I disable copying of cells in an Excel spreadsheet using VBA, or disable the copy command and right-click mouse button?

    Thanks

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Disable copying in a spreadsheet (97)

    This is by Chip Pearson and I found it:

    http://www.j-walk.com/ss/excel/eee/eee020.txt

    Steve

    ---The objective is to prevent people cutting/copying and pasting when your workbook is open.---

    Run DisableCutAndPaste from a suitable event procedure (e.g. Workbook_Open or Worksheet_Activate) and EnableCutAndPaste
    from another (e.g. Workbook_Close or Worksheet_Deactivate).

    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

  3. #3
    New Lounger
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable copying in a spreadsheet (97)

    Thanks Steve, that is great.

    Regards

    Melissa <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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