+ Reply to Thread
Results 1 to 11 of 11

Command Button that shows Hidden Sheets - Needs Password Protection

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    988

    Command Button that shows Hidden Sheets - Needs Password Protection

    Hello All,

    I have a Command Button that shows all hidden sheets in the workbook... Here is the code

    Sub ShowDataSheets()
    Dim ws As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            ws.Visible = xlSheetVisible
        Next ws
    End Sub
    I am needing to code the macro so that the user must enter a specific password in order to use the Command Button.

    Any solutions in mind!


    Sorry about missing the Code Tags!


    Best Regards

    John
    Last edited by JJFletcher; 10-17-2014 at 12:28 AM.

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

    Re: Command Button that shows Hidden Sheets - Needs Password Protection

    Hi, JJFletcher

    please have a look at Forum Rule#3 to understand why you are asked to apply code-tags to your procedure.

    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 Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Command Button that shows Hidden Sheets - Needs Password Protection

    Hi, John,

    please try
    Sub ShowDataSheets()
    
    Dim ws As Worksheet
    Const cstrPW As String = "strangePW"
    
    If InputBox(Prompt:="Enter the password", Title:="Enter Password", Default:="enter password here") = cstrPW Then
      For Each ws In ThisWorkbook.Worksheets
        ws.Visible = xlSheetVisible
      Next ws
    Else
      MsgBox "Sorry, wrong password", vbInformation, "No luck here"
    '  ThisWorkbook.Close True
    End If
    
    End Sub
    Thanks for adding the code-tags.

    Ciao,
    Holger

  4. #4
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Command Button that shows Hidden Sheets - Needs Password Protection

    Absolutely Perfect - SOLVED

    Again Sorry for missing the Rule #3

    Thanks so Much!

    John

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

    Re: Command Button that shows Hidden Sheets - Needs Password Protection

    Hi, John,

    thanks for the feedback.

    A small alteration for the number of tries which might be of interest to you as well:

    Sub ShowDataSheets()
    
    Dim ws As Worksheet
    Static lngTries As Long
    
    Const cstrPW As String = "strangePW"
    Const clngMAX As Long = 3
    
    If InputBox(Prompt:="Enter the password", Title:="Enter password", Default:="enter password here") = cstrPW Then
      For Each ws In ThisWorkbook.Worksheets
        ws.Visible = xlSheetVisible
      Next ws
    Else
      lngTries = lngTries + 1
      MsgBox "Sorry, wrong password", vbInformation, "Missed trie: " & lngTries & " of " & clngMAX & " tries"
      If lngTries = clngMAX Then ThisWorkbook.Close True
    End If
    
    End Sub
    Ciao,
    Holger

  6. #6
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Command Button that shows Hidden Sheets - Needs Password Protection

    Thanks so much... I saw somewhere that I can specify to only open specific sheets desired - not all sheets in the Workbook, but ones that only have "Data" as part of it's description...

    Can the code below also be coded to only allow the sheets with "Data" be shown?

    Sub ShowDataSheets()
    
    Dim ws As Worksheet
    Static lngTries As Long
    
    Const cstrPW As String = "strangePW"
    Const clngMAX As Long = 3
    
    If InputBox(Prompt:="Enter the password", Title:="Enter password", Default:="enter password here") = cstrPW Then
      For Each ws In ThisWorkbook.Worksheets
        ws.Visible = xlSheetVisible
      Next ws
    Else
      lngTries = lngTries + 1
      MsgBox "Sorry, wrong password", vbInformation, "Missed trie: " & lngTries & " of " & clngMAX & " tries"
      If lngTries = clngMAX Then ThisWorkbook.Close True
    End If
    
    End Sub


    John
    Last edited by JJFletcher; 10-17-2014 at 12:57 AM.

  7. #7
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    988

    Re: [SOLVED]Command Button that shows Hidden Sheets - Needs Password Protection

    Ciao,
    Holger... Absolutely Superb... Works just as I want it to... Thanks So Much ... Really
    Last edited by JJFletcher; 10-17-2014 at 01:06 AM. Reason: SOLVED

  8. #8
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Command Button that shows Hidden Sheets - Needs Password Protection

    OK.... One more question....

    In your password code - when the User enters the Password - Others can see the Password being entered - is there a ways to make it so others can't tell what is being typed by seeing ******* when the user enters the password?

    Best Regards

    John

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

    Re: Command Button that shows Hidden Sheets - Needs Password Protection

    Hi, John,

    if you want to use the InputBox the only way I know is to use API to mask the characters being entered. I would recommend you have a look at UserForms where you may add a Textbox (PasswordChar can be given there) which would mask the entry without further notice. A simple UserForm could consist of one label for some explanation what to do, one textbox for the entry, one commandbutton for cancelling and one for submit with the code to check like given above (and the command to unload the userform)

    Ciao,
    Holger

  10. #10
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Command Button that shows Hidden Sheets - Needs Password Protection

    Ok - Great advise - Thanks much... Please disregard my private message - I did not think you would come back to this issue sine you solved it for me

+ 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. [SOLVED] Format all cells in all sheets to Protection Hidden on visible and hidden tabs
    By DeRo22 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-28-2014, 03:17 PM
  2. [SOLVED] COmmand button requiring password, if password ok, unhide sheet.
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-04-2012, 09:43 AM
  3. Replies: 1
    Last Post: 06-22-2012, 11:53 AM
  4. Password protection for a macro button
    By ramakavin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-08-2008, 05:22 PM
  5. Protection and hidden sheets
    By daddioja in forum Excel General
    Replies: 1
    Last Post: 02-15-2007, 10:03 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