1
votes

I am using Excel 2010 and I have a workbook with sheets that must be protected, but I still want to make changes to locked cells from a VBA macro. I found out that this is easily possible by running

myWorksheet.Protect UserInterfaceOnly:=True

However if a user opens another workbook in the same Excel Application, they might accidentaly run another macro which might mess up my worksheet.

Is there an option like UserInterfaceOnly to protect from macros of other workbooks as well?

Otherwise is it safe to only temporarly use UserInterfaceOnly and fully protect at the end of any of my macros again, or would this be dangerous due to concurrency?

1
Good Question. If the other workbook opened after the protected workbook then it will become the active workbook. If the first protected workbook somehow becomes active again then yes, the second workbook's code may alter the protected workbook with VBA code.The only other way I can think of is to use the normal protection and simply unprotect each sheet when you need to make changes and immediately protect it after. You could enhance security with Sheet1.Unprotect Password:="Special" - type your code - Sheet1.Protect Password:="Special"John Muggins

1 Answers

1
votes

The safest thing to do is protect the worksheets at the end of your code setting UI-only back to false.