What is the best way of protecting a specific Excel workbook?
I have an inherited script that includes the following common lines at the end:
ActiveSheet.Protect "my-password"
ActiveWorkbook.Protect "my-password"
However, I've noticed that as the script can take a few minutes to run users often switch to a new unrelated workbook whilst it solves - whatever else they are working on. The password protection is then inherited by the unrelated workbook upon the completion of the macro - since whatever other Excel file the user is working within is now "Active" (presumably? this is my reading of the problem).
The above script is in a workbook that can be renamed to whatever the user chooses, and be saved in any number of directories. How can I ensure that only the original excel file is locked/unlocked by the Macro, when other workbooks are in use?
I am sure there are many ways to do this, but which is the most foolproof method?
NOTE: using office 365
ThisWorkbookinstead ofActiveWorkbook- DeanActiveSheetto a worksheet object in the event your users are changing workbooks., You will then be able to still reference that "ActiveSheet" regardless if they change workbooks. - DeanThisSheet.Protect- PetrichorThisSheetdoes not exist. You will be able to useThisWorkbookas a Workbook object. To use a Worksheet object I would recommend reading my comment above yours. - Dean