Thursday, January 21, 2016

Excel VBA- Excel sheets protection


By Ajeet Kumar

EXCEL VBA: CREATE PASSWORD TO EACH SHEET OF A WORKBOOK

Sub pSetPasswd()

    Dim sht As Worksheet

    On Error GoTo lblError

    Application.ScreenUpdating = False

    For Each sht In ThisWorkbook.Sheets

        sht.Protect Password:="MyPassWord", UserInterfaceOnly:=True

        sht.Protect

    Next

    Application.ScreenUpdating = True

lblError:

If Err <> 0 Then

    MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description

End If

End Sub

No comments:

Post a Comment

Hot Topics