VBA Enable cell-drag-and-drop?

merlin_the_magician

Active Member
Joined
Jul 31, 2002
Messages
480
I have a worksheet in which i disabled CutCopyMode and CellDragAndDrop functions through VBA in order to prevent users from messing up the sheet.
Code is simple and looks like this:

With Application
.CutCopyMode = False
.CellDragAndDrop = False
End With

Works lovely, unfortunately just a little to much... after closing the workbook the functions remain disabled.
How can I re-enable these functions on exit of the workbook, and where shoud i put the code?



With Application
.CutCopyMode = False
.CellDragAndDrop = False
End With
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Ivan... dumb question how am i to write this code? I have been trying, but i don't know how to call the before close procedure
 
Upvote 0
in 'this workbook'

Private Sub workbook_BeforeClose(Cancel As Boolean)
With Application
.CutCopyMode = True
.CellDragAndDrop = True
End With
End Sub
 
Upvote 0
Mind,

the application cutcopymode only cancel a selection. I does not prevent the user from selecting and copying. You can prevent this by the following in this workbook:


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub

This will as far as I can see prevent the user from pasting the cells all over the place. ( I have had the same problem with user making a mess of a very nice layout by copying and pasting)
Luke
 
Upvote 0
Thank you for the code Luke. I have been messing around with the "Private Sub workbook_BeforeClose(Cancel As Boolean)".

As for the second script, for the moment the first method seems satisfy my security needs.

In the workbook, there really is not that much to copy at all. The initial idea was to prevent users from applying the DragAndDrop option that will allow them to "auto-fill" a range. When they do, numerous validations and conditional formats may be removed or altered causing severe damage to the worksheet.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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