We help IT Professionals succeed at work.
Get Started

Excel - VBA disabled copy, paste, and cut with password

holemania
holemania asked
on
427 Views
Last Modified: 2016-02-11
I need to prevent users from being able to copy, paste, cut, and drag/drop to my excel worksheet.  I found the code I need, but I also need to allow some people to be able to copy/paste.  Is it possible to integrate a password with the following?  Once password is enter, you can copy/paste, and then if you do again, you need to re-enter password?

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_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
 Cancel = True
 MsgBox "Right click menu deactivated." & vbCrLf & _
 "Cannot copy or ''drag & drop''.", 16, "For this workbook:"
 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

Open in new window

Comment
Watch Question
Social distance - Wear a mask - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE