Discussion Locked

Protected Excel Sheet With Macro Changes

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have an Excel worksheet that needs to be protected to keep users from making changes. This worksheet is reading in data from a linked program and then outputting this information into the spreadsheet by way of macros. If data is out of bounds I also change the fill color of a cell to RED. It works great without protection but once protected causes an error in the macro because it is not allowed to change the spreadsheet. Is there a way to give authority to the macros but not the keyboarduser?

4 replies

by dklippert

Add a Un-protect/Protect macro that is called by your main macro when it needs to update.
Perhaps:
Sub ProTect_NotProtect
ActiveWorkbook.Protect := "Password"
'....Run some code ....
ActiveWorkbook.UnProtect := "Password"
End Sub

by dklippert

I suppose reversing the two lines makes more sense; Unprotect and then (re)Protect. (:')

This discussion is closed to new replies.