by Allen Wyatt
(last updated November 28, 2020)
Matthew notes that a user can rather easily right-click on a worksheet tab and thereby move or copy a worksheet to another workbook. He is looking for a way to prevent this behavior; he needs a way to stop a user from making a copy of a worksheet or moving it.
This is harder than one would, at first, think. The standard approach is to protect the workbook. (Use the Protect Workbook tool on the Review tab of the ribbon.) Provided you protect the structure, Excel will disable the Move or Copy Sheet option.
Perhaps, for some reason, you don't want to protect the workbook. In that case you can create macro solutions that may do the trick for you. For instance, let's say that you have a macro in the code module for the worksheet itself. You could have that macro, as part of its functioning, check for the presence of some other data in the workbook or some system variable. (The data should be external to the worksheet, but still in the workbook.) If the presence is detected, then everything functions as you would want.
If, however, the user copies or moves the worksheet to another workbook, then obviously the other data or variable will not be there. If your macro (which was moved with the worksheet) doesn't detect the required data, then the macro could do whatever action you feel is appropriate, including deleting the worksheet.
A different macro-based approach would be to utilize two events for the worksheet, in this manner:
Private Sub Worksheet_Activate() ThisWorkbook.Protect "Hello" End Sub
Private Sub Worksheet_Deactivate() ThisWorkbook.Unprotect "Hello" End Sub
These two event handlers simply protect the workbook whenever the worksheet is selected and, conversely, unprotect it when a different worksheet is selected. Why do this? For the reason mentioned earlier—protecting the workbook can turn off the ability to move or copy worksheets. Because the user would always need to select the worksheet before copying or moving, the acts are disabled because the event handlers kick into play.
Remember, though, that if your objective is to stop the user from copying the data and/or formulas on the worksheet, you need to think beyond the user possibly copying or moving the worksheet. The user can always copy cell contents from the worksheet to a different worksheet, which might defeat what you are trying to do.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13804) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
If you have a worksheet protected, it may not be immediately evident that it really is protected. This tip explains some ...Discover More
Need to know if a worksheet or workbook is currently protected? Excel provides some tell-tale signs, but here are some ...Discover More
Want to hide certain columns within a worksheet so the contents are not visible to others? The answer lies in formatting ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.