One can also do this without unprotecting and then protecting the sheet each time. There' something called UserInterfaceOnly in Excel when you protect a sheet through VBA (I haven't come across a similar feature in the Excel interface itself, and probably Microsoft has a logic also, to which I can relate to).
So to do this, you could project all the sheets, making it True for UserInterfaceOnly, and then continue with your normal codes, without having to Unprotect and Protect each time.
What I generally do (if this is required) is, in the workbook code module,
Or in a code moduleCode:Private Sub Workbook_Open() Dim sht As Object For Each sht In ThisWorkbook.Sheets sht.Unprotect "PASSWORD" sht.Protect UserInterfaceOnly:=True, Password:="PASSWORD" Next sht End Sub
Now, though the sheet is protected, any manipulation of data on the protected sheet using VBA will not be hindered due to the UserInterfaceOnly:=True argument in the protectionCode:Private Sub Auto_Open() Dim sht As Object For Each sht In ThisWorkbook.Sheets sht.Unprotect "PASSWORD" sht.Protect UserInterfaceOnly:=True, Password:="PASSWORD" Next sht End Sub




Reply With Quote
Bookmarks