+ Reply to Thread
Results 1 to 12 of 12

[VBA CODE] Password Protect a hidden sheet while using other code

  1. #1
    Registered User
    Join Date
    07-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    2010 Pro
    Posts
    25

    [VBA CODE] Password Protect a hidden sheet while using other code

    Hi, Everyone.

    I am currently using a VB code to enforce the enabling of Macros as my workbook heavily relies on VB and Macros.

    The code is as follows:
    Please Login or Register  to view this content.
    the sheet "Supervisor Review" is soft hidden (can be un-hidden by right clicking on the sheet tabs). What I am trying to do is require a password to unhide this specific sheet and this sheet only. I tried to use the basic "Protect Workbook" structure, but that interfers with the enforce macro VB code. Any ideas?

    Thanks in advance!

  2. #2
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    Try something like this the sheet's code module.
    Please Login or Register  to view this content.
    Downside is that each time you (re)activate the sheet the password is required. But that can be solved by setting some public variable.
    Let me know if you need help with that.
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  3. #3
    Registered User
    Join Date
    07-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    2010 Pro
    Posts
    25

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    This works almost perfect! I really do not mind having to enter the password every time the sheet is hidden/unhidden, in fact I think I prefer it in case the workbook is emailed to someone after unhiding said sheet.

    I noticed that when you right click > unhide the sheet, prior to requesting the password it still loads the sheet. Although you cannot scroll to see the full data, without entering the password, you can still see a good chunk. Any way to block that?

  4. #4
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    Here's an demo not requiring a password when the sheet's already visible.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    2010 Pro
    Posts
    25

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    EDIT: I see why you need that addition now, Thank you!

    I wonder though, if there is a way to make a dummy sheet, or white out the screen, etc. until someone enters the password to prevent them from seeing ANY data.
    Last edited by cityinbetween; 09-25-2014 at 03:43 PM.

  6. #6
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    If you change the code from post #2 to this that will be solved.
    Please Login or Register  to view this content.

  7. #7
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    This demo will not require a password all the time and not predisplay the sheet.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    07-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    2010 Pro
    Posts
    25

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    hmm, there seems to be an issue with the last code. It does indeed ask for a password prior to showing the sheet, but after the password is entered, it throws you on another sheet. When you try to click on the needed sheet it automatically hides it again...

    Here is blank copy of the workbook.
    (removed attachment)

    BTW, Thank you for all your help!!!
    Last edited by cityinbetween; 09-25-2014 at 05:06 PM.

  9. #9
    Registered User
    Join Date
    07-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    2010 Pro
    Posts
    25

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    This worked great, I had to modify the "Activate" line but seems to be working great now!! Thank you very much! Your knowledge and time is very much appreciated! (rep added)

    If you do have sometime, I am pretty new to VB and am eager to learn. Could you explain why this particular code needed the separate module to run? (this is the first time I run into that..)

    Quote Originally Posted by Tsjallie View Post
    This demo will not require a password all the time and not predisplay the sheet.

  10. #10
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    why this particular code needed the separate module to run?
    I assume you're referring to the Module1.
    VBA requires public variables to be declard in a module if you want them to be available throughout your application.
    In this case however it could also be declared in the sheet's code module as it is only referred within the context of that sheet.

  11. #11
    Registered User
    Join Date
    07-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    2010 Pro
    Posts
    25

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    got it! Thanks again for all your help!! It is very much appreciated!

  12. #12
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: [VBA CODE] Password Protect a hidden sheet while using other code

    You're welcome. Thx for the rep

+ 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] Password protect sheet - modify code
    By eXtremer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-02-2013, 08:46 AM
  2. [SOLVED] Unprotect VBA - Run Code - Protect again (password is known)
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-10-2012, 09:35 AM
  3. Need to rewrite protect code so that it will work with a hidden sheet.
    By mrgillus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2009, 08:17 PM
  4. Protect Sheet & Password Protect Code
    By KLahvic in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-13-2009, 04:08 PM
  5. [SOLVED] Protect Sheet - VB code to specify password
    By Darin Kramer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2005, 05:06 AM

Tags for this Thread

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