Thanks Thanks:  0
Likes Likes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Password issues on Workbook Open Event

  1. #1
    Board Regular
    Join Date
    Jul 2013
    Posts
    95
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Password issues on Workbook Open Event

    When I run this code I get a message that the password is incorrect. But it is correct. Do I need to state it another way?
    Code:
    Private Sub Workbook_Open()
        Sheets("Employees").Unprotect Password = "Password"
        Range("F8").Select
        Sheets("Employees").Protect Password = "Password"
    End Sub
    Necessity is the mother of invention
    Laziness is the mother of efficiency

  2. #2
    Board Regular
    Join Date
    Jul 2002
    Location
    Derbyshire, UK
    Posts
    1,605
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Password issues on Workbook Open Event

    There must be an error with the password spelling or case, because there is no problem with the code.
    Hope that helps.

    Free Excel sample DataBase Form here

    royUk's web site

    "making Excel work for you"

  3. #3
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,210
    Post Thanks / Like
    Mentioned
    40 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Password issues on Workbook Open Event

    Actually, the code is wrong. You're passing False as the password. It should be:
    Code:
    Private Sub Workbook_Open()
        Sheets("Employees").Unprotect Password:="Password"
        Range("F8").Select
        Sheets("Employees").Protect Password:="Password"
    End Sub
    Note the colons!

  4. #4
    Board Regular
    Join Date
    Jul 2002
    Location
    Derbyshire, UK
    Posts
    1,605
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Password issues on Workbook Open Event

    Should have used my eyes Rory I didn't notice the missing :.
    Hope that helps.

    Free Excel sample DataBase Form here

    royUk's web site

    "making Excel work for you"

  5. #5
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,210
    Post Thanks / Like
    Mentioned
    40 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Password issues on Workbook Open Event

    I'd be lying if I said I'd never done it!

  6. #6
    Board Regular
    Join Date
    Jul 2013
    Posts
    95
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Password issues on Workbook Open Event

    Thanks to both!
    To ensure accuracy, I copy and paste when it comes to passwords (that's how I knew the password was correct). But then I tried to create the rest of the formula from scratch. If only I'd been lazier at that point ....
    Necessity is the mother of invention
    Laziness is the mother of efficiency

  7. #7
    Board Regular
    Join Date
    Jul 2002
    Location
    Derbyshire, UK
    Posts
    1,605
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Password issues on Workbook Open Event

    Just go with

    Code:
    Private Sub Workbook_Open()   
     Sheets("Employees").Unprotect "Password"   
     Range("F8").Select    
    Sheets("Employees").Protect "Password"
    End Sub
    Hope that helps.

    Free Excel sample DataBase Form here

    royUk's web site

    "making Excel work for you"

  8. #8
    Board Regular
    Join Date
    Jul 2013
    Posts
    95
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Password issues on Workbook Open Event

    Simple is good - Thanks, royUK
    Necessity is the mother of invention
    Laziness is the mother of efficiency

  9. #9
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,210
    Post Thanks / Like
    Mentioned
    40 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Password issues on Workbook Open Event

    Of course, I should have just shamelessly self-promoted and pointed you here: Excel Matters Blog Archive What’s in a colon?

  10. #10
    Board Regular
    Join Date
    Jul 2013
    Posts
    95
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Password issues on Workbook Open Event

    Quote Originally Posted by RoryA View Post
    Of course, I should have just shamelessly self-promoted and pointed you here: Excel Matters Blog Archive What’s in a colon?
    I checked it out, and now I feel compelled to ask:
    What, is any, is the difference between
    .Unprotect Password:="Password"
    and
    .Unprotect Password "Password"
    Necessity is the mother of invention
    Laziness is the mother of efficiency

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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