+ Reply to Thread
Results 1 to 3 of 3

Perform action on select sheets upon opening workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    06-20-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Question Perform action on select sheets upon opening workbook

    Hi all, I have a workbook with 10 sheets, and I have the below code to un-protect, enable outlining and re-protect all sheets upon opening the workbook:

    Private Sub Workbook_Open()
    
    Dim wksht As Worksheet
    For Each wksht In ThisWorkbook.Sheets
        With wksht
            .Unprotect "password"
            .EnableOutlining = True
            .Protect "password", contents:=True, userInterfaceOnly:=True
        End With
    Next wksht
    
    Worksheets("Instructions & Notes").Rows("1:2").Hidden = True
    
    End Sub
    What if I'd like to perform the action on all sheets except "Sheet 1" and "Sheet 2"? Thanks in advance!

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Perform action on select sheets upon opening workbook

    What if I'd like to perform the action on all sheets except "Sheet 1" and "Sheet 2"?
    If you know the name of these worksheets, then something like:

    Private Sub Workbook_Open()
    
    Dim wksht As Worksheet
    For Each wksht In ThisWorkbook.Sheets
        If wksht.Name <> "Sheet1" _
        And wksht.Name <> "Sheet2" Then
            With wksht
                .Unprotect "password"
                .EnableOutlining = True
                .Protect "password", contents:=True, userInterfaceOnly:=True
            End With
        End If
    Next wksht
    
    Worksheets("Instructions & Notes").Rows("1:2").Hidden = True
    
    End Sub

  3. #3
    Registered User
    Join Date
    06-20-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Perform action on select sheets upon opening workbook

    Thanks Steve, works!

+ 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