+ Reply to Thread
Results 1 to 18 of 18

Password that unhides all sheets in "read only mode"/protected workbook

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Password that unhides all sheets in "read only mode"/protected workbook

    I am using following macro to hide and show sheets for specific password. I'm wondering if I can get a "public" password that would unhide ALL sheets but in "read only mode" or "protected workbook", meaning if someone again signs in with user password, he'll be able to input data normaly.


    Option Explicit
    
    Sub PasswordChk() 'input password, unhide sheets'
    Dim Pwd As String
        
        Select Case LCase(Application.InputBox("Please enter your password to access:", "PASSWORD CONFIRMATION", Type:=2))
            Case "alpha"
                Sheets("Sheet1").Visible = xlSheetVisible
                Sheets("Sheet2").Visible = xlSheetVisible
                Sheets("Sheet3").Visible = xlSheetVisible
               
             
            Case "male"
                Sheets("Sheet4").Visible = xlSheetVisible
                Sheets("Sheet5").Visible = xlSheetVisible
                Sheets("Sheet6").Visible = xlSheetVisible
          
                
            Case "one"
                Sheets("Sheet7").Visible = xlSheetVisible
                Sheets("Sheet8").Visible = xlSheetVisible     
            
        End Select
    Sheets("MAIN").Select
        Range("B1").Select
        MsgBox ("Please choose process."), , "ACCESS!"
    End Sub

    with:

    Option Explicit
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean) 'when close, saves document, hides sheets'
    Dim ws As Worksheet
    
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> "MAIN" Then ws.Visible = xlSheetVeryHidden
        Next ws
        
        ThisWorkbook.Save       'saves wb again without asking
        
    End Sub
    Thank you for suggestions!

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    Maybe I'm misunderstanding. You want the user to input a password, have all sheets unhide in read only or protected mode and still allow the user to input data manually? If that's the case, then I don't think it would be possible for them to enter anything into the sheet as read only/protected mode wont allow it to happen.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    No, let's say each time you open the document you have a chance to view it in different options. One of the options should be unhide all sheets in "protected sheet view", after you close the document (with a second code mentioned above) it hides sheets again and by entering a password next time opening the document you view it as defined in macro options.

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    This will unhide all sheets in protected mode...
    Sub ProtectUnhideSheets()
    Dim ws As Worksheet
    Dim myPassword As String
        myPassword = "1111"
        
    
        For Each ws In ThisWorkbook.Worksheets
            ws.Protect Password:=myPassword
                ws.Visible = True
            Next ws
    
    End Sub
    Assign it to a button for the user to run it, or, put it in a Workbook_Open event to have it run when the workbook opens.

  5. #5
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    Thank you!

    How can I add an option when workbook is closed it should "un-protect" all sheets to enable user to input data next time the workbook is opened?

  6. #6
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    Put this in ThisWorkbook
    Private Sub Workbook_Open()
    Dim ws As Worksheet
    Dim myPassword As String
        myPassword = "1111"
        
        For Each ws In ThisWorkbook.Worksheets
            ws.Unprotect Password:=myPassword
        Next ws
        
    End Sub

  7. #7
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    Not sure I understood.

    First macro does not ask me for password, second option has no effect on workbook.

  8. #8
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    ok, for the first code try..
    Sub ProtectUnhideWorksheets()
        Dim pass As String
        Dim ws As Worksheet
        Dim myPassword As String
            myPassword = "1111"
        
        pass = InputBox("Enter Password")
            If pass <> "password" Then MsgBox "Incorrect password."
                
        For Each ws In ThisWorkbook.Worksheets
                ws.Protect password:=myPassword
            ws.Visible = True
        Next ws
        
    End Sub
    This will ask for a password and unhide all hidden sheets in protected mode. The password is password as in the code.

    The 2nd code unprotects all the sheets when the workbook opens. You can assign that to a button instead

  9. #9
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    I appreciate the amended code.

    I would need a code when workbook is being closed it disables "protected view" and returns document in same format as before activating the macro.

    Any ideas?
    Thank you!

  10. #10
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    This will do it, place it in the ThisWorkbook section
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim ws As Worksheet
    Dim myPassword As String
        myPassword = "1111"
        
        For Each ws In ThisWorkbook.Worksheets
            ws.Unprotect Password:=myPassword
        Next ws
        
    End Sub

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,956

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    Oh, and just because a worksheet is protected and hidden doesn't mean you can't unhide it
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,956

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    For this:
    Dim myPassword As String
        myPassword = "1111"
    You could write:
    Const myPassword As String = "1111"

    Regards, TMS

  13. #13
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    Thanks for the info Trevor, but I'm afraid I'm not familiar with
    Const myPassword As String = "1111"
    As for the hidden part, very true, if they know there are hidden sheets, they can unhide them easily with a click or 2.

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,956

    Re: Password that unhides all sheets in "read only mode"/protected workbook


  15. #15
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,956

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    Const is a constant, same as a variable but, well, constant, not changing. So, for something like a password, you can use a constant rather than defining a variable and setting its value somewhere else in the code.

    As for the hidden sheet(s), just making the point that just because it is hidden, even very hidden, it's not safe or secure.

    Regards, TMS

  16. #16
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    TMS,
    I've tried using Const for the password, and I like it, it's a bit cleaner looking in the code than the Dim etc. Thanks again.

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,956

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    @gmr4evr1: You're welcome. Thanks for the rep.

  18. #18
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Password that unhides all sheets in "read only mode"/protected workbook

    No problem.

+ 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 bypass password prompt and open workbook in read only mode.
    By Tazyote in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2012, 05:04 AM
  2. "read only" notification on un protected sheet
    By mfs in forum Excel General
    Replies: 1
    Last Post: 12-29-2010, 06:07 AM
  3. Inserting Data from Text Box to "Password" Protected Cell
    By bbarrene in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-19-2010, 02:46 PM
  4. "IF" sheet is protected with password
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2008, 09:46 AM
  5. [SOLVED] Password-Protected Workbook not showing "in use by another user"
    By Jim Jackson in forum Excel General
    Replies: 1
    Last Post: 07-13-2006, 10:15 AM
  6. Replies: 3
    Last Post: 05-31-2006, 05:10 AM
  7. I would want protect my sheets of excel from a "password recovery" software... How?
    By -= Luca =- in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2006, 09:10 PM
  8. [SOLVED] Can never edit my projects, everything is always "read-only mode"
    By Maury Markowitz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-29-2005, 11:06 AM

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