You can protect all sheets from user changes, but still allow VBA scripts to make changes using the "UserInterfaceOnly" option. This workaround allows you to run any VBA script on sheets without having to protect and unprotect each time:
Dim ws as Worksheet Dim pwd as String pwd = "" ' Put your password here or Each ws In Worksheets ws.Protect Password:=pwd, UserInterfaceOnly:=True Next ws
Deprotection is the same as the solution proposed by Ben Hoffstein:
Dim ws as Worksheet Dim pwd as String pwd = "" ' Put your password here For Each ws In Worksheets ws.Unprotect Password:=pwd Next ws
You can access this macro using the / shortcut button. In Excel 2010, you right-click on the shortcut bar and select "Customize Shortcut Bar". In the drop-down menu, select the command, select "Macros". Then click on the VBA script that you created to protect (or unprotect). Finally, click "Add β" and then "OK" to save it.
Chrisb
source share