+ Reply to Thread
Results 1 to 3 of 3

VBA to Restrict Excel File Copy, Paste, Cut, DragNdrop & Move Sheet

Hybrid View

ibuhary VBA to Restrict Excel File... 12-12-2018, 11:47 PM
PaulSP8 Re: VBA to Restrict Excel... 12-17-2018, 04:27 AM
ibuhary Re: VBA to Restrict Excel... 12-18-2018, 07:06 AM
  1. #1
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Question VBA to Restrict Excel File Copy, Paste, Cut, DragNdrop & Move Sheet

    Hello,

    I am looking for simple VBA Codes to execute upon opening an excel file to prevent user from following tasks:
    - Cut
    - Copy
    - Paste
    - Drag and Drop
    - Move/Copy Sheet

    The codes should run automatically upon opening the file without any prompt.

    Appreciate any help.

  2. #2
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: VBA to Restrict Excel File Copy, Paste, Cut, DragNdrop & Move Sheet

    Hi

    The following code disables Cut, Copy and Paste and *I think* drag and drop but I'm not 100% sure what you mean by that.

    This needs to be placed in the "ThisWorkbook Module" and the Workbook will need to be saved and reopened before it takes effect;

    Private Sub Workbook_Activate()
    Application.CutCopyMode = False
    Application.OnKey "^c", ""
    Application.CellDragAndDrop = False
    End Sub
     
    Private Sub Workbook_Deactivate()
    Application.CellDragAndDrop = True
    Application.OnKey "^c"
    Application.CutCopyMode = False
    End Sub
     
    Private Sub Workbook_WindowActivate(ByVal Wn As Window)
    Application.CutCopyMode = False
    Application.OnKey "^c", ""
    Application.CellDragAndDrop = False
    End Sub
     
    Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
    Application.CellDragAndDrop = True
    Application.OnKey "^c"
    Application.CutCopyMode = False
    End Sub
     
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Application.CutCopyMode = False
    End Sub
     
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Application.OnKey "^c", ""
    Application.CellDragAndDrop = False
    Application.CutCopyMode = False
    End Sub
     
    Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
    Application.CutCopyMode = False
    End Sub
    The only way I know to stop people from moving and copying a sheet is to disable the menu completely, this is done by;

    Private Sub Workbook_Activate()
    Application.CommandBars("Ply").Enabled = False
    End Sub
    
    Private Sub Workbook_Deactivate()
    Application.CommandBars("Ply").Enabled = True
    End Sub
    If you want this to work in conjunction with disabling Cut, Copy and Paste then you'll need to replace the two Subs in the first set of code and use them like this;

    Private Sub Workbook_Activate()
    Application.CommandBars("Ply").Enabled = False
    Application.CutCopyMode = False
    Application.OnKey "^c", ""
    Application.CellDragAndDrop = False
    End Sub
     
    Private Sub Workbook_Deactivate()
    Application.CommandBars("Ply").Enabled = True
    Application.CellDragAndDrop = True
    Application.OnKey "^c"
    Application.CutCopyMode = False
    End Sub

  3. #3
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: VBA to Restrict Excel File Copy, Paste, Cut, DragNdrop & Move Sheet

    Okay let me try this

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to copy a cell, paste it to another sheet, then move down, without moving formulas
    By ahalliwell in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2017, 07:40 AM
  2. Replies: 7
    Last Post: 07-04-2014, 05:34 AM
  3. Copy / Paste Values Only one sheet into another file from a multi sheet excel file
    By srisri201012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2013, 12:56 PM
  4. [SOLVED] Move data from excel 1 to excel 2 and also copy file name as sheet name in excel 2
    By akulas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-25-2012, 04:20 AM
  5. [SOLVED] Copy, paste, then move to a new sheet.
    By Cyberpawz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2012, 02:12 PM
  6. Replies: 1
    Last Post: 10-17-2005, 04:05 AM
  7. Replies: 1
    Last Post: 01-04-2005, 06:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1