+ Reply to Thread
Results 1 to 22 of 22

Password Protection not accepting password

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Password Protection not accepting password

    Hi there,

    Can anyone spot why this code doesn't work. It runs, but will not accept the password I set, which for testing was a simple lower case "hello" placed in A1 on sheet 4.

    Private Sub Button2_Click()
        Dim Pswd As String
        Pswd = Sheet4.Cells(1, 1)
        
        Sheet1.Protect Password:=Pswd, UserInterFaceOnly:=True
    End Sub
    Kind regards

    Rob

  2. #2
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Password Protection not accepting password

    Pswd = Sheets("Sheet4").Cells(1, 1).Value
    Sheets("Sheet1").Protect Password:=Pswd, UserInterFaceOnly:=True

  3. #3
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Password Protection not accepting password

    To clear something up, to unlock the sheet, I am going -Review Tab - Unprotect Sheet and then entering the same password that is being pointed at. This code works so long as I type in the password into the script, but not if I try to reference it on a cell somewhere. i can't get this to work even if the password is on a cell on the same sheet that is right in front of me.

    What am I doing wrong here please?

  4. #4
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Password Protection not accepting password

    Sorry I was wrong, it doesn't work at all, not even with a password. I beleive the syntax is right, but I guess I am not putting it in the right place. but right now my only way of editing this sheet now is deleting it and starting again, that is not really what I want it to do.

  5. #5
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Password Protection not accepting password

    Hmm, no that doesn't work either, I wonder what I am doing wrong.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Password Protection not accepting password

    I can only guess the cell you are referring to in the code is not the one you think it is.
    Everyone who confuses correlation and causation ends up dead.

  7. #7
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Password Protection not accepting password

    Use below code to unlock the sheet.
    Sub test()
    Pswd = Sheets("Sheet4").Cells(1, 1).Value
    Sheets("Sheet1").Unprotect Password:=Pswd
    End Sub
    And try this code to lock, just to make sure you are referring to correct cell.

    Sub test1()
    Pswd = Sheets("Sheet4").Cells(1, 1).Value
    MsgBox "password is - " & Pswd
    Sheets("Sheet1").Unprotect Password:=Pswd
    End Sub

  8. #8
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Password Protection not accepting password

    Ah, ok, so I need to unlock it with a script, I can't use the ribbon?

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Password Protection not accepting password

    No, the ribbon should work too.

  10. #10
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Password Protection not accepting password

    You can unlock using ribbon provided you know the password used to protect. Since I am doubting you are not referring to a cell you think you are, above code would exactly get the password used to lock.

  11. #11
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Password Protection not accepting password

    Thank you haripopuri, this does work, yet not with the ribbon, it will only unlock via script. Could that be a bug in the program, or do you have to specify that you want to be able to use the ribbon?

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Password Protection not accepting password

    Can you post a workbook showing this? If it is a bug, I'd like to get it filed as that's pretty serious. (Note: I find it hard to believe it would not have been found before this though)

  13. #13
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Password Protection not accepting password

    Unfortunately no, I can't upload the workbook as I am at work, all I did was open a new workbook, add an extra worksheet so there was a worksheet 4 in there, then I used this script and run them as needed to get an idea of what was working or not. I am running windows 7 using microsoft office 2007 enterprise.

    Option Explicit
    
    Dim Pswd As String
    
    Private Sub testing()
        Pswd = Sheets("Sheet4").Cells(1, 1).Value
        Sheets("Sheet1").Protect Password:=Pswd, UserInterFaceOnly:=True
    End Sub
    
    Sub test1()
        Pswd = Sheets("Sheet4").Cells(1, 1).Value
        MsgBox "password is - " & Pswd
        Sheets("Sheet1").Unprotect Password:=Pswd
    End Sub
    
    Sub test()
        Pswd = Sheets("Sheet4").Cells(1, 1).Value
        Sheets("Sheet1").Unprotect Password:=Pswd
    End Sub
    Kind regards

    Rob

  14. #14
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Password Protection not accepting password

    Ok lets do this. Run below macro once and notice the message box that appear after you run this macro What does it say...

    Sub testing()
        Pswd = Sheets("Sheet4").Cells(1, 1).Value
    Msgbox Pswd
        Sheets("Sheet1").Protect Password:=Pswd, UserInterFaceOnly:=True
    End Sub
    and what happen when you use the same password shown in the box from ribbon to unlock?

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Password Protection not accepting password

    I don't have 2007 here but it's fine in 2010. I will double-check 2007 later but I would be very surprised if it fails there. It would have to have been spotted by now if it's a bug in 2007.

    One thing to note: if you had already protected Sheet1 with a different password than the one in Sheet4 cell A1, that password would still be in effect, not the one the code tried to apply, but that would impact both methods of unprotecting the sheet.

    One other check - you don't have Caps Lock on by any chance?

  16. #16
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Password Protection not accepting password

    No, I did check for that I even typed the password (which in this case was "One") into another cell then copied and pasted it, though that didn't work, as I was unable to paste into the password box, but it would have flagged up a caps lock issue if that had been the case.

  17. #17
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Password Protection not accepting password

    Hello Rob K,

    I have done exactly what you did, and even went one step furher by saving it as a Excel 2003 .xls version.

    I am runing Excel 2007, and it works fine without any issues.

    Please try the attached sample Workbook.

    Regards.
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  18. #18
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Password Protection not accepting password

    Hi, hopefully, I have successfully attached this for you.

    Regards

    Rob
    Attached Files Attached Files

  19. #19
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Password Protection not accepting password

    What password are you trying? You know there's a space on the end of "One " in A1 on Sheet4?

  20. #20
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Password Protection not accepting password

    Hello Rob K,

    Please try your attached, revised Workbook now.

    Regards.
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Password Protection not accepting password

    Wow, that is very astute to spot that one, thank you so much, yes it all works well now, it must be my dyslexic thumb being a little over keen on the space bar.

  22. #22
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Password Protection not accepting password

    Phew. It got me worried for a while.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Password Protection
    By imtiaz ahmed in forum Excel General
    Replies: 3
    Last Post: 02-21-2010, 07:53 AM
  2. password protection-is there anyway to put a password on running a macro in excel?
    By Solarissf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2008, 10:06 AM
  3. Password Protection
    By cdp690803 in forum Excel General
    Replies: 1
    Last Post: 08-15-2007, 05:43 PM
  4. Password Protection
    By ElsiePOA in forum Excel General
    Replies: 6
    Last Post: 07-25-2006, 12:25 AM
  5. Password protection
    By Noemi in forum Excel General
    Replies: 2
    Last Post: 01-24-2006, 01:25 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1