Results 1 to 15 of 15

Access to a hidden spreadsheet

Threaded View

Supdem Access to a hidden spreadsheet 11-12-2012, 03:35 PM
dogberry Re: Access to a hidden... 11-12-2012, 03:47 PM
Supdem Re: Access to a hidden... 11-12-2012, 03:53 PM
dogberry Re: Access to a hidden... 11-12-2012, 04:11 PM
Supdem Re: Access to a hidden... 11-12-2012, 04:28 PM
abousetta Re: Access to a hidden... 11-12-2012, 04:33 PM
ChemistB Re: Access to a hidden... 11-12-2012, 04:34 PM
abousetta Re: Access to a hidden... 11-12-2012, 04:37 PM
Supdem Re: Access to a hidden... 11-12-2012, 05:21 PM
Supdem Re: Access to a hidden... 11-12-2012, 05:05 PM
abousetta Re: Access to a hidden... 11-12-2012, 05:25 PM
Supdem Re: Access to a hidden... 11-12-2012, 05:39 PM
abousetta Re: Access to a hidden... 11-12-2012, 07:17 PM
Shytott Re: Access to a hidden... 11-13-2012, 05:02 AM
abousetta Re: Access to a hidden... 11-13-2012, 07:37 AM
  1. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Access to a hidden spreadsheet

    In a standard module add this code:

    Option Explicit
    
    Sub HideDataSheet()
      Dim Answer$
      ' If Data sheet is visible then hide it
        If Sheets("Data").Visible = True Then
          ' Select the button
            ActiveSheet.Shapes("Button 1").Select
          ' Change the text on the button to reflect the status of the button
            Selection.Characters.Text = "Unhide Sheet"
          ' Hide the Data sheet
            Sheets("Data").Visible = xlVeryHidden
          ' Select cell A1
            Range("A1").Select
          ' Show a message that the sheet is hidden
            MsgBox "Data sheet is now hidden.", vbInformation
        Else
    ResumeHere:
          ' If Data sheet is hidden then ask for a password
            Answer = InputBox("Password", "Please enter administrative password.")
            If Answer = "Hello" Then
              ' Unhide the data sheet if the password is correct
                Sheets("Data").Visible = xlSheetVisible
              ' Select the button
                ActiveSheet.Shapes("Button 1").Select
              ' Change the text on the button to reflect the status of the button
                Selection.Characters.Text = "Hide Sheet"
              ' Select cell A1
                Range("A1").Select
              ' Show a message that the sheet is hidden
                MsgBox "Data sheet is now visible.", vbInformation
            Else
              ' If nothing is entered or the InputBox is cancelled then exit the sub
                If Len(Trim(Answer)) = 0 Then Exit Sub
              ' If password is incorrect then show a message
                If MsgBox("Password is incorrect." & vbCrLf & "Would you like to try again?", vbOKCancel) = vbCancel Then Exit Sub Else GoTo ResumeHere
            End If
        End If
    End Sub
    Then add a button and link the button to this subroutine.
    Don't forget to add a password to the vba project or anyone can just open and change the code.

    It's a bit long but it checks several possible scenarios and gives message boxes along the way to guide the end user.

    Hope this helps.

    abousetta
    Last edited by abousetta; 11-12-2012 at 04:36 PM. Reason: Highlighted areas you might want to change
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

Thread Information

Users Browsing this Thread

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

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