+ Reply to Thread
Results 1 to 11 of 11

Command Button that shows Hidden Sheets - Needs Password Protection

Hybrid View

  1. #1
    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
    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

  2. #2
    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.

  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,

    if the left 4 characters of the sheetnames are Data:
    '...
      For Each ws In ThisWorkbook.Worksheets
        If Left(ws.Name, 4) = "Data" Then
          ws.Visible = xlSheetVisible
        End If
      Next ws
    If Data is contained anywhere in the sheetname:
      For Each ws In ThisWorkbook.Worksheets
        If InStr(1, ws.Name, "Data") > 0 Then
          ws.Visible = xlSheetVisible
        End If
      Next ws
    Ciao,
    Holger

+ 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