[Solved] VBA : Setting xlUnlocked

  • I set the property of my worksheet to xlUnlocked so thet the protected cells can't be selected. This makes a neater project I believe. The problem is when I save it and re-open the workbook the property is set bact to the default. How can I do this in VBA when the workbook opens?

  • This will do the trick


    If you want it for more worksheets, put it in for loop

    Code
    Private Sub Workbook_Open()
    With Worksheets(1)
        .EnableSelection = xlUnlockedCells
        .Protect Contents:=True, UserInterfaceOnly:=True
    End With
    
    
    End Sub

    Thanks: ~Yogendra

  • Thanks. That did the trick. I don't realy understand the (1) after the worksheet. If you have time could you explain that to me. My books aren't too in depth on that.

  • Worksheets(1) does the processing for first worksheet in the workbook.


    If you want to protect all your sheets, you can put it in For loop or do the processing on specific sheet with
    follwoing code, where "Protected_Sheet" is the name of the sheet on which the processing is needed.

    Thanks: ~Yogendra

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!