Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Protect Or Unprotect Sheet Only If Password Matches

  1. #11
    Junior Member
    Join Date
    Jun 2013
    Posts
    16
    Rep Power
    0
    There is no macro option to assign...I place this code in the sheet...could it be that I want the macro to work with a shape and not the commandbutton
    Code:
    
    Private Sub CommandButton1_Click()
    
        Dim strPassword As String
        Const strActualPassword As String = "ABCD"
        strPassword = InputBox("Please enter the password", "Protect/Unprotect Sheet")
        
        If strActualPassword = strPassword Then
            If Me.CommandButton1.Caption = "PROTECT SHEET" Then
                Me.CommandButton1.Caption = "UNPROTECT SHEET"
                Me.Protect Password:=strPassword
            Else
                Me.CommandButton1.Caption = "PROTECT SHEET"
                Me.Unprotect Password:=strPassword
            End If
        Else
            MsgBox "Invalid Password"
        End If
        
    End Sub

  2. #12
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. VBA Code To Protect Sheet With Only A Few Cells Unlocked
    By rich_cirillo in forum Excel Help
    Replies: 3
    Last Post: 07-04-2013, 06:47 PM
  2. How do I get Vlookup to return multiple matches?
    By HANOOF in forum Excel Help
    Replies: 1
    Last Post: 06-04-2013, 10:06 PM
  3. Replies: 0
    Last Post: 04-20-2013, 10:07 AM
  4. Password Holder
    By littleiitin in forum Download Center
    Replies: 3
    Last Post: 01-01-2013, 03:22 PM
  5. CheckBox to see password
    By Ingolf in forum Excel Help
    Replies: 9
    Last Post: 08-26-2012, 11:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •