+ Reply to Thread
Results 1 to 3 of 3

Using Group and Ungroup on multiple sheet when password protected

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    New Hampshire
    MS-Off Ver
    Excel 2010
    Posts
    84

    Using Group and Ungroup on multiple sheet when password protected

    Hi all,

    I'm trying to make this code work for multiple sheets but everything I've tried won't work. Here is the code so far:

    Private Sub Workbook_Open()
    With Sheet1
    .Unprotect Password:="Secret"
    .EnableOutlining = True
    .Protect Password:="Secret", UserInterfaceOnly:=True
    End With
    End Sub

  2. #2
    Registered User
    Join Date
    05-17-2013
    Location
    New Hampshire
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Using Group and Ungroup on multiple sheet when password protected

    Found the answer...(problem)!!! I had 2 different passwords. Once I corrected this and used the same password on both sheets, the code below worked!!!!


    Private Sub Workbook_Open()
    Dim wks As Worksheet
    For Each wks In ThisWorkbook.Worksheets
    With wks
    .Unprotect Password:="Secret"
    .EnableOutlining = True
    .Protect Password:="Secret", UserInterfaceOnly:=True
    End With
    Next wks
    End Sub


    This code will be executed automatically each time the workbook is opened, and protect all sheets. It will also allow users to "Group & Ungroup"

  3. #3
    Registered User
    Join Date
    05-17-2013
    Location
    New Hampshire
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Using Group and Ungroup on multiple sheet when password protected

    This is actually cleaner:

    You need VBA for this, and the end user will need to allow macros for this to work.
    Press Alt+F11 to activate the Visual Basic Editor.
    Double-click ThisWorkbook, under Microsoft Excel Objects in the project explorer on the left hand side.


    Copy the following code into the module that appears:


    Private Sub Workbook_Open()
    For Each Sheet In Worksheets
    Sheet.Unprotect Password:="Secret"
    Sheet.EnableOutlining = True
    Sheet.Protect Password:="Secret", UserInterfaceOnly:=True
    Next
    End Sub


    This code will be executed automatically each time the workbook is opened, and protect all sheets.
    Make sure password is the same for all sheets!!!!
    ----------------------------------------------------

+ 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