+ Reply to Thread
Results 1 to 28 of 28

Create a message box when someone uses the drag/drop feature

  1. #1
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Create a message box when someone uses the drag/drop feature

    To start, I am VBA illiterate, so whatever your response, please dumb it down for a 3 year old. Thanks. Make that a 2 year old.

    Our office uses an Excel spreadsheet for travel approval. There are tabs for each month so 12 tabs (plus hidden tabs for my admin use)

    I have conditional formatting and data validation in each tab. The problem is when travelers copy/paste and drag/drop - it screws up my conditional formatting (and data validation), plus we've had issues with people copying previous travel and not changing the travelers names so we don't know who is actually going on the trip.

    I created a message box to show when the spreadsheet it opened that tells people NOT to do any of that, but of course they ignore it.

    I've found a code to prevent the copy/paste, so that hurdle is done (I do have a question about that too though). But I've searched online and have found nothing to prevent the drag and drop except to disable it for the entire Excel program. I don't want that. If there is a way to prevent it for only this ONE workbook, that would be great.

    However, since I don't think that is possible, I am trying to create a message box that whenever someone DOES execute the drag/drop, and message box appears telling the user this feature isn't allowed.

    Ideally a code could be written to then undo whatever the user did by drag/drop.

    I hope all that made sense. Again, there are tabs for each month, so whatever the solution, it needs to be applied to them all.

    Thank in advance!!

    Oh, and about the solution I found to prevent copy/paste.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.CutCopyMode = False
    End Sub

    This code works great. But I would like to be able to toggle this on and off easily. Is there a way to add key strokes so I could do something like Ctrl + Alt + D (or whatever)? Just a set of key strokes that would turn the above code on and off (because I hate the idea of adding and deleting the code whenever I need to copy and paste).

    Thank again.

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Create a message box when someone uses the drag/drop feature

    Try this code....place it in the ThisWorkbook module
    Please Login or Register  to view this content.
    The shortcut keys may not work though.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Create a message box when someone uses the drag/drop feature

    If i may, it might be a better idea to put the CellDragAndDrop lines in the Workbook Activate and Deactivate events, then drag and drop will be enabled if the user switches to another open workbook.

    On second reading perhaps all the code should be moved...
    Last edited by cytop; 03-15-2017 at 02:13 PM.

  4. #4
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    Hi gmr4evr1,

    Thanks for responding. Unfortunately, the code did not work. I created a Module1 in ThisWorkbook, and pasted your code.

    I am still able to use the drag and drop, and the copy/paste works too. The shortcut keys don't seem to do anything either (I am not worried about that as much though).

  5. #5
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    Quote Originally Posted by cytop View Post
    If i may, it might be a better idea to put the CellDragAndDrop lines in the Workbook Activate and Deactivate events, then drag and drop will be enabled if the user switches to another open workbook.

    On second reading perhaps all the code should be moved...
    Hi cytop, how would I do this to try?

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Create a message box when someone uses the drag/drop feature

    I created a Module1 in ThisWorkbook
    The code goes in the ThisWorkbook code module, not a standard code module... You'll find the Activate and Deactivate events using the 2 dropdowns at the top of the code window. Select 'Workbook' in the left hand drop down and the various events will be available from the right hand dropdown.

  7. #7
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Create a message box when someone uses the drag/drop feature

    Don't create a module, place the code in ThisWorkbook.....double click ThisWorkbook then paste the code.
    MKE2014 Disable Drag Drop and Cut Copy.xlsm
    I haven't been able to get the shortcut keys to work either.
    Last edited by gmr4evr1; 03-15-2017 at 02:25 PM. Reason: Added sample file

  8. #8
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Create a message box when someone uses the drag/drop feature

    If i may, it might be a better idea to put the CellDragAndDrop lines in the Workbook Activate and Deactivate events, then drag and drop will be enabled if the user switches to another open workbook.

    On second reading perhaps all the code should be moved...
    Doing the code that I provided and the way I suggested works. OP should be able to have multiple workbooks open and the cut/copy, drag/drop functions will only be disabled in the workbook that contains the code. Other workbooks are not affected when that workbook is open.

  9. #9
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    Thank you both! The drag and drop has been disabled for what looks like just this workbook. I opened a different spreadsheet and drag/drop worked for that one. Yay!

    But the copy/paste still worked.

    When I added this code below to the specific tab (module?) it works. I am going to see if I can add a shortcut key to that code which works.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.CutCopyMode = False
    End Sub

    Thanks again! I'll keep you posted.

  10. #10
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Create a message box when someone uses the drag/drop feature

    Sorry about that, I hadn't tested the CutCopy part of the code, but I'm glad you were able to get it to work.

  11. #11
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    Quote Originally Posted by gmr4evr1 View Post
    Sorry about that, I hadn't tested the CutCopy part of the code, but I'm glad you were able to get it to work.
    I wasn't able to figure out how to add a shortcut key, but thank you again for getting me so much closer to what I need.

    Instead of a shortcut key, could a button be created to trigger the copy/paste on and off? I don't want the other users to see the button, so I could put it on one of my hidden tabs just for me.

    Any suggestions would be much appreciated!

    Thanks!
    (I am leaving work shortly so I will pick this back up in the morning. You have lots of time to ponder.) :-D

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Create a message box when someone uses the drag/drop feature

    Hello MKE2014,

    You could play around with this code in the attachment, and change it to your liking.

    If you need further help, please let me know.

    In ThisWorkbook Code;

    Please Login or Register  to view this content.
    And in a Standard Module;

    Please Login or Register  to view this content.
    Regards.
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  13. #13
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Create a message box when someone uses the drag/drop feature

    Winon,
    Not sure about anyone else, but I'm unable to open the file. When it downloads, it shows it's an xlsx file extension.

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Create a message box when someone uses the drag/drop feature

    @gmr4evr1,

    That is strange?

    Please try this one.

    Regards.
    Attached Files Attached Files

  15. #15
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Create a message box when someone uses the drag/drop feature

    I was able to open that one, but the code errors out on each "Onkey" line and on the .CutCopyMode = False lines. I'll go through it when I can, probably something on my end.

  16. #16
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    Quote Originally Posted by Winon View Post
    @gmr4evr1,

    That is strange?

    Please try this one.

    Regards.
    Hi Winon,

    Thanks!! I see the term "toggle" in the code. As I said, I am VBA illiterate, so does that mean you've included a way for me to "toggle" these features on and off? I didn't see anything in the code to show me what that could be, so I am guessing "toggle" means something else.

    And why does the formula bar need to be hidden? I hate the fact that I don't speak VBA. I have tried, and tried to no avail to learn the language.

    Thanks again.

  17. #17
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Create a message box when someone uses the drag/drop feature

    Hi MKE2014,

    Thank you for the feedback.

    Would you like Buttons to "toggle" these features on and off?

    And why does the formula bar need to be hidden?
    That is to sidestep one of the flaws in Excel, where you cannot prevent Copy from the Formula Bar and paste to another Cell. The average Excel user is unaware that they could Copy and Paste that way, and I have not yet encountered an incident where someone was able to figure that one out!

    Regards.

  18. #18
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    Quote Originally Posted by Winon View Post
    Hi MKE2014,

    Thank you for the feedback.

    Would you like Buttons to "toggle" these features on and off?



    That is to sidestep one of the flaws in Excel, where you cannot prevent Copy from the Formula Bar and paste to another Cell. The average Excel user is unaware that they could Copy and Paste that way, and I have not yet encountered an incident where someone was able to figure that one out!

    Regards.
    Yes, a button to toggle these feature on and off would be soooooooo awesome!! Thanks!!! I have hidden tabs and I can hide the button there.

  19. #19
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Create a message box when someone uses the drag/drop feature

    O.K. MKE2014,

    Here you go. Enjoy!

    Regards.
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    Quote Originally Posted by Winon View Post
    O.K. MKE2014,

    Here you go. Enjoy!

    Regards.
    Hi Winon, I wasn't able to open the file.

  21. #21
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Create a message box when someone uses the drag/drop feature

    Hello MKE2014,

    Hi Winon, I wasn't able to open the file.
    That is very strange!

    Please try this one.

    Regards.
    Attached Files Attached Files
    Last edited by Winon; 03-22-2017 at 12:33 PM.

  22. #22
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    Thank you!! Sorry for delay; work has been soooo crazy this week.

    When I have the "Copy Off" selected and try to paste something, I get an error: "Run-time error '1004;" Method 'Undo' of object '_Application' failed"
    I click on debug and it highlights Application.Undo in the code, no matter which sheet I am using.

    Also, why does sheet 1 have the #1 and Hello; sheet 2 have the #2 and Cheers and Sheet 3 have the # and Bye written on them? Were those tests?

    Thanks again!

  23. #23
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Create a message box when someone uses the drag/drop feature

    Hi MKE2014,

    Oops, sorry my bad!

    It was the wrong Workbook version!

    Also, why does sheet 1 have the #1 and Hello; sheet 2 have the #2 and Cheers and Sheet 3 have the # and Bye written on them? Were those tests?
    Correct, only test data.

    Please try this one.

    Regards.
    Attached Files Attached Files

  24. #24
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    I can't open the new workbook. I get the same error message as the one you posted on 3-16. I'll see if I can attached a screen shot.

  25. #25
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    screenshot.jpg

    I hope this image comes through ok.

  26. #26
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Create a message box when someone uses the drag/drop feature

    Hello MKE2014,

    I am confused.

    Please try it in the .xls Format.

    Regards.
    Attached Files Attached Files

  27. #27
    Registered User
    Join Date
    01-30-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Create a message box when someone uses the drag/drop feature

    Nope, that one didn't work either. Are you able to tell me how you fixed the code in the file I was able to download? I really, really appreciate your help. I'm sorry the file is being difficult.

  28. #28
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Create a message box when someone uses the drag/drop feature

    O.K. MKE2014,

    Ready, Steady, Here we go:

    In ThisWorkbook Code;

    Please Login or Register  to view this content.
    In a Standard Module, Code;

    Please Login or Register  to view this content.
    In Sheet1, Code;

    Please Login or Register  to view this content.
    In Sheet2, Code; Repeat for every other Sheets you may have;

    Please Login or Register  to view this content.
    Hope this solves your problem.

    Kind Regards.

+ 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. Disable drag/copy feature
    By InvalidTxtString in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2016, 01:23 PM
  2. drag and drop feature in skydrive
    By DouglasHardy in forum Office 365
    Replies: 0
    Last Post: 09-10-2013, 10:03 AM
  3. Drag feature in Excel 2010 not working
    By Maheshgx in forum Excel General
    Replies: 4
    Last Post: 08-13-2012, 09:02 AM
  4. How to use use automatic cell fill drag feature while string inside???
    By Daniel.Blesener in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2012, 10:07 AM
  5. Create a drag and drop list with shapes
    By The Intern in forum Excel General
    Replies: 3
    Last Post: 03-28-2011, 09:53 PM
  6. Cell - Drag feature
    By Vinodsralian in forum Excel General
    Replies: 3
    Last Post: 07-24-2010, 02:26 PM
  7. [SOLVED] the drag feature in combining cells won't work
    By Annxqz in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-04-2006, 08:20 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