excelvba

worksheet open event, using UserInterfaceOnly to protect all sheets - not working


I want to have all worksheets protected, but allow VBA to make changes

I usually have no problem accomplishing that, but this time I also want to allow the user to edit images

The end result is that the sheets are not protected

In the open worksheet event, I have the following code:

Dim wsSheet As Worksheet

For Each wsSheet In Worksheets
    wsSheet.Protect DrawingObjects:=False, UserInterfaceOnly:=True
Next

This works fine if I leave out the DrawingObjects:=False part - but as the code is, the sheets are unprotected

What I am doing wrong please?


Solution

  • Try

    Dim wsSheet As Worksheet
    
    For Each wsSheet In Worksheets
    wsSheet.Unprotect
        wsSheet.Protect DrawingObjects:=False, UserInterfaceOnly:=True
    Next