+ Reply to Thread
Results 1 to 5 of 5

Modifying VBA to password protect numerous sheets within the same workbook

Hybrid View

MattRNR Modifying VBA to password... 04-08-2016, 05:59 AM
igormigor Re: Modifying VBA to password... 04-08-2016, 06:16 AM
MattRNR Re: Modifying VBA to password... 04-13-2016, 09:29 PM
igormigor Re: Modifying VBA to password... 04-14-2016, 09:44 AM
MattRNR Re: Modifying VBA to password... 04-15-2016, 02:16 AM
  1. #1
    Registered User
    Join Date
    10-24-2012
    Location
    Adelaide
    MS-Off Ver
    Excel 2019
    Posts
    79

    Modifying VBA to password protect numerous sheets within the same workbook

    G’day Excel Forum

    I'm having some trouble augmenting a bit of VBA code and I'm hoping someone can help me out

    I would like to be able to add passwords to multiple sheets within a workbook.

    I’ve found a code online that has allowed me to add a single password to a single sheet (the ‘database’ sheet in the attached example) however I’ve been unable to work out how to modify it to work for other sheets in the same workbook.

    In the attached workbook the code can be found in the ‘ThisWorkbook’ excel object, ideally I’d like to add passwords to sheets T1, T2 and T3 sheets as well, however I can’t work out how to modify the code to do this.

    Has anyone any idea how to do this?

    Cheers for any advice

    Regards

    MattRNR

    P.S. I've also been having some trouble putting attachments onto this forum so here's hoping there is actually an attachment on here (incidentally I was able to get the attachments to work while using excel general and didn't wan't to waste the forums spontaneous decision to work so appologies for not posting on the VBA specific page)
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague
    MS-Off Ver
    Excel 2013
    Posts
    161

    Re: Modifying VBA to password protect numerous sheets within the same workbook

    I've recently used this code. It will put password to all of the sheets in the workbook when you open the workbook.

    Private Sub Workbook_Open()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        	ws.Protect Password:=" Vesper"
    Next ws
    End Sub

  3. #3
    Registered User
    Join Date
    10-24-2012
    Location
    Adelaide
    MS-Off Ver
    Excel 2019
    Posts
    79

    Re: Modifying VBA to password protect numerous sheets within the same workbook

    G'day Igormigor

    Appreciate this code mate, alas this doesn't quite solve the problem

    This prevents modifications to the sheets; however I need the sheets to be invisible without entering a password as with the 'Vesper' password on the ‘database’ sheet of the attached example.

    Effectively all I need to do is get that same code to work for the T1, T2 and T3 sheets but with a different password.

    Sounds simple but can’t work it out for the life of me, any thoughts?

    Appreciate the help

    Regards
    MattRNR

    P.S. I appologize for the lateness of my response I've been out bush for a couple of days without internet

  4. #4
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague
    MS-Off Ver
    Excel 2013
    Posts
    161

    Re: Modifying VBA to password protect numerous sheets within the same workbook

    Hi MattRNR,
    I have problem with suppressing the sheet not to be shown until the password is entered. Some conflict is appearing that is putting the code in the loop, hiding all sheets. :s
    The best I can do is the code below. I know its not what you requested, but maybe can give you idea how to proceed.
    Sorry could not help you.



    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    
    Application.ScreenUpdating = False
    
    NumNam = ActiveSheet.Name
    Num = ActiveSheet.Index
    
    If NumNam = "Search" Then
        For Each myWorksheet In Worksheets
            myWorksheet.Visible = True
        Next
    End If
    
    ' The password for the diferent sheets are defined below
    If NumNam = "Database" Then Pass = "Vesper" Else
    If NumNam = "T1" Then Pass = "T1" Else
    If NumNam = "T2" Then Pass = "T2" Else
    If NumNam = "T3" Then Pass = "T3" Else
    
    If NumNam <> "Search" Then
        If Application.InputBox("Enter Password", "Password") <> Pass Then
            MsgBox "Incorrect Password", vbCritical, "Error"
                Application.EnableEvents = False
    ' If the password is incorrect, it poens "Search" sheet
            Sheets("Search").Select
                Application.EnableEvents = True
        Else
        End If
    End If
        
        Application.ScreenUpdating = True
    
    End Sub

  5. #5
    Registered User
    Join Date
    10-24-2012
    Location
    Adelaide
    MS-Off Ver
    Excel 2019
    Posts
    79

    Re: Modifying VBA to password protect numerous sheets within the same workbook

    No worries mate, this has given me a couple of idea's I can run with.

    appreciate the help mate

    Regards

    MattRNR

+ 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. Replies: 2
    Last Post: 11-17-2014, 04:28 PM
  2. Password protect sheets disbled in shared workbook
    By DavidBW in forum Excel General
    Replies: 0
    Last Post: 05-08-2013, 11:49 AM
  3. Trying to build Macro to password protect all sheets in workbook
    By eatmorecheese in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2012, 12:07 PM
  4. Password protect sheets in workbook
    By Querl in forum Excel General
    Replies: 2
    Last Post: 01-30-2011, 06:05 PM
  5. Lock and password protect only cells with formulas on all sheets in a workbook
    By steve in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-10-2006, 03:29 AM
  6. View limited sheets in workbook based on logon/password protect
    By Nicole Seibert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2006, 05:50 PM
  7. Replies: 2
    Last Post: 07-16-2005, 11:05 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