Consulting

Results 1 to 5 of 5

Thread: Code will protect but not unprotect

  1. #1
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location

    Code will protect but not unprotect

    Hi

    I've used code to protect a sheet with a password. It works fine

    When I use code to unlock with the very same password, I get a "wrong password" error??

    When I try to to a manual unlock I also get the password error

    What the blazes is going on???

    Thanks

    BD
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Trailing spaces, embedded spaces?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Nope, there are no trailing spaces.
    Code is:

    [vba]Sub LockMe()
    '
    ' LockMe Macro
    '
    Dim myPassword As String
    myPassword = "password"
    '
    ActiveCell.Offset(-1, 0).Range("A1").Copy
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteValidation, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    With ActiveSheet
    .Protect Password = myPassord
    .EnableSelection = xlUnlockedCells
    End With
    End Sub
    Sub UnlockMe()
    '
    ' UnlockMe Macro
    '
    Dim myPassword As String
    myPassword = "password"
    '
    ActiveSheet.Unprotect Password = myPassword
    With Selection.Validation
    .Delete
    .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
    :=xlBetween
    .IgnoreBlank = True
    .InCellDropdown = True
    .IMEMode = xlIMEModeNoControl
    .ShowInput = True
    .ShowError = True
    End With
    Selection.FormulaR1C1 = "=NOW()"
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveCell.Offset(-1, 0).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    End Sub[/vba]

    I just don't get it.
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    They both should be

    [vba]
    Password:= myPassord[/vba]

    not

    [vba]
    Password = myPassord[/vba]

    and one time you use myPassord the other myPassword. Aren't you using Option Explicit yet?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Quote Originally Posted by xld
    They both should be

    [vba]
    Password:= myPassord[/vba]

    not

    [vba]
    Password = myPassord[/vba]

    and one time you use myPassord the other myPassword. Aren't you using Option Explicit yet?
    Thanks Bob, I feel so silly and childish.
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

Posting Permissions

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