+ Reply to Thread
Results 1 to 9 of 9

How to check password of protected sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    How to check password of protected sheet

    hi,

    I have a macro where i protect one of the sheets in the file. I have the password hardcoded into the vba code. However, the user could change the password manually. So want i want to do is at the beginning of the macro check to make sure that the password in the vba code is the password used to protect the sheet. Any good ideas on how to do this?

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: How to check password of protected sheet

    Hi, welchs101,

    avoid giving the password to the users.

    Sub welchs101()
    Dim strPW As String
    On Error Resume Next
    ActiveSheet.Unprotect "mypassword"
    If Err <> 0 Then
      While Len(strPW) = 0 Or strPW = ""
        strPW = InputBox("Enter new password:")
      Wend
    End If
    ActiveSheet.Unprotect strPW
    End Sub
    No guarantee that the password delivered will fit.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to check password of protected sheet

    Hi,

    If the sheet is password protected then how could a user change the password unless they know what it is?

    If you feel they may go behind the scenes to look in the VBE for the pw then protect the VBE with a password so that they have no way of seeing inside the macros and discovering it.

    The point about passwords is that they're not meant to be easily discoverable and if there was some macro code that would get the password (in order to check it against a known value), then that would rather defeat the object.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    Re: How to check password of protected sheet

    thanks. you are both right. but circumstances are such that i have to give the password to certain individuals who are not computer savy. currently they know how to unprotect a sheet manually but i am trying to do this via vba but i have to check for the possibility of someone changing the password just in case.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to check password of protected sheet

    Hi,

    Given that the sheet is protected, what sort of access do you need to give to users? i.e. what do you want to allow them to change. Don't forget that you can unlock specific cells that are eligible to be changed when protection is switched on.

    In addition note that when protecting the sheet there are various options you can tick(like deleting rows, sorting, filtering) so that these actions can still take place despite the protection.

  6. #6
    Forum Contributor
    Join Date
    12-24-2014
    Location
    little ole England
    MS-Off Ver
    2013
    Posts
    116

    Re: How to check password of protected sheet

    you could create a user password that runs the macro

    the macro could UN-protect the sheet using a password that looks like an instruction to the novice user reading the code

    the macro would reset protected worksheet status

    so the sheet would remain protected and if user changes their password it only enables them to run macro not access protected sheet

    however refer to previous comments point of a password is to protect then only those allowed access should have password

    other way is to hold the protected sheet in separate protected workbook that user can only call to not open
    ◄Ŧя?μвŁ?►
    By Name & By Nature

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to check password of protected sheet

    If only give selected people the password and you are concerned that those people will un/re protect the sheet with a different password, that sounds like 1) they need to be trained to never do that or 2) there is an HR problem with malicious employees, a problem that VBA cannot solve.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  8. #8
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    Re: How to check password of protected sheet

    thanks for the suggestions.

  9. #9
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: How to check password of protected sheet

    First of all, Microsoft password protection is very weak, and a savvy user can 'beat the system'.

    To defeat the efforts of unsavvy users, you could give the user an 'Encrypted' copy of the password. Users would have to use a command button or some other way to access a Macro which would have the User enter the encrypted password. The Macro would then decrypt the password, it and give the user access to the sheet.

    This method only works if users don't have direct access to the Worksheet while it is unprotected. For example, a user would select a cell and then click a CommandButton that runs a Macro. The Macro would prompt the user for the data, and the Macro would unprotect/protect the worksheet as required. In order to run the Macro the first time, the User would have to enter the Encrypted Password.

    See the attached sample workbook, which is based on a printable Character XOR (Exlusive Or) algorithm courtesy of Sebastion L. (circa 2003) at: http://www.codetoad.com/visual_basic_better_xor.asp
    It seems superior to other XOR algorithms I have seen, as the other algorithms usually have NON-Printable characters in the 'Encrypted Password'.

    Lewis
    Attached Files Attached Files

+ 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. How to check/verify password of protected sheet is what you think it is
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2012, 02:31 PM
  2. [SOLVED] Enable check box in protected sheet + group check boxes
    By Dexxterr in forum Excel General
    Replies: 4
    Last Post: 08-02-2006, 07:05 AM
  3. no password for protected sheet
    By TJaques in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-27-2006, 12:50 PM
  4. Check for Sheet Password Protected, Unprotect with multiple passwo
    By David in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2006, 01:25 PM
  5. password protected a check box
    By Glendon MacBurnie in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-27-2005, 05:37 PM

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