+ Reply to Thread
Results 1 to 4 of 4

Auto hide & protect worksheets before closing

Hybrid View

  1. #1
    Registered User
    Join Date
    06-04-2011
    Location
    paris
    MS-Off Ver
    Excel 2010
    Posts
    4

    Auto hide & protect worksheets before closing

    Hi folks,

    I wrote the following code to hide & password protect an excel sheet :

    Sub Hideconfidential()
    Worksheets("confidential").Visible = xlSheetVeryHidden
    End Sub
    Sub UnHideconfidential()
    rspn = InputBox("Enter Password")
    If rspn <> "Pw" Then Exit Sub
    Worksheets("confidential").Visible = xlSheetVisible
    End Sub
    How could I alter it so that it hides and protects this sheet automatically before closing the workbook ?

    Thank you!
    Last edited by Leith Ross; 11-15-2011 at 03:26 PM. Reason: Added Code Tags

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Auto hide & protect worksheets before closing

    Hi magnum206

    in the workbook module place

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Worksheets("confidential").Visible = xlSheetVeryHidden
    Me.Protect ("pike")
    End Sub
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    06-10-2014
    Posts
    6

    Re: Auto hide & protect worksheets before closing

    I am trying to implement this in a spreadsheet I have and I cannot get the code to work.

    I have 5 sheets
    I want sheet "Info" to remain visible
    But sheets, times, Email, Print, Run Comp, Leaderboard to hide when sheet is closed.

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Auto hide & protect worksheets before closing

    Quote Originally Posted by intervals View Post
    I am trying to implement this in a spreadsheet I have and I cannot get the code to work.

    I have 5 sheets
    I want sheet "Info" to remain visible
    But sheets, times, Email, Print, Run Comp, Leaderboard to hide when sheet is closed.
    Firstly, You will need to FORCE users to enable macros.

    Multiple versions of 'Force Enable Macros' code exists (just google). Here's one: http://xl-central.com/force-users-to...-workbook.html

    After implementing code to Force users to enable macros, you will need to modify it to suit your requirements.

    So using the example given at xl-central,

    Private Sub HideAllSheets()
    Const strWSInfo as string = "Info"
    Const strWSConfidential as string = "confidential"
    
    'N.B. I don't recommend you rely on hardcoded tab names to identify specific sheets.
    ' Because they only work as long as nobody renames the tab
    ' Learn to use sheet code names instead
    
    Const strPwdConfidential as string = "Pw"
    
        'Declare the variable
        Dim Sh As Object
        
        'Display the warning sheet
        Sheets(Warning).Visible = xlSheetVisible
        
        'Hide every sheet, except the warning sheet
        For Each Sh In Sheets
            If Sh.Name <> Warning And Sh.Name <> strWSInfo Then
                Sh.Visible = xlSheetVeryHidden
                If Sh.Name = strWSConfidential  Then: Sh.Protect strPwdConfidential  
            End If
        Next Sh
       
    End Sub
    Last edited by mc84excel; 06-11-2014 at 08:33 PM. Reason: clarify
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

+ Reply to Thread

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