+ Reply to Thread
Results 1 to 8 of 8

How can I Collapse or Expand Outline in Protected Sheets

  1. #1
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Question How can I Collapse or Expand Outline in Protected Sheets

    Hi,

    I have outline on three protected worksheets in a workbook, and I want other users to be able to collapse and expand the outline while the worksheets are protected. I entered the following code (which works fine):

    Option Explicit
    Sub auto_open()
    With Worksheets("REPORT1")
    .Protect Password:="test", userinterfaceonly:=True
    .EnableOutlining = True
    End With
    End Sub

    I then try the following (but it's not working):

    Option Explicit
    Sub auto_open()
    With Worksheets("REPORT1")
    With Worksheets("REPORT2")
    With Worksheets("REPORT3")
    .Protect Password:="test", userinterfaceonly:=True
    .EnableOutlining = True
    End With
    End Sub

    Any help, please?

    Thank you,
    Gos-C
    Using Excel 2010 & Windows 10
    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Gos-C
    Hi,

    I have outline on three protected worksheets in a workbook, and I want other users to be able to collapse and expand the outline while the worksheets are protected. I entered the following code (which works fine):

    Option Explicit
    Sub auto_open()
    With Worksheets("REPORT1")
    .Protect Password:="test", userinterfaceonly:=True
    .EnableOutlining = True
    End With
    End Sub

    I then try the following (but it's not working):

    Option Explicit
    Sub auto_open()
    With Worksheets("REPORT1")
    With Worksheets("REPORT2")
    With Worksheets("REPORT3")
    .Protect Password:="test", userinterfaceonly:=True
    .EnableOutlining = True
    End With
    End Sub

    Any help, please?

    Thank you,
    Gos-C
    Hi,

    try a variation of
    Please Login or Register  to view this content.
    Let me know how you go
    ---
    Si fractum non sit, noli id reficere.

  3. #3
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408
    Hi Bryan,

    It didn't work.

    I continue to get the message:

    You cannot use this command on a protected sheet. To unprotect the sheet, use the unprotect sheet command (Tools menue, Protection submenu). You may be prompted for a password.

    Gos-C

  4. #4
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Gos-C
    Hi Bryan,

    It didn't work.

    I continue to get the message:

    You cannot use this command on a protected sheet. To unprotect the sheet, use the unprotect sheet command (Tools menue, Protection submenu). You may be prompted for a password.

    Gos-C
    Hi,

    I can.

    To test for yourself, start Macro recorder, then manually go Tools, Protection, Protect Sheet, and tick the third item (format cells).

    Then rightmouse and format the cell.

    Stop recording and compare this to your code.

    Let me know how you go.
    ---

  5. #5
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408
    Hi Bryan,

    I noticed you suggested code has "AllowFormattingCells." Would that allow the outlining level symbols to work when the sheet is protected?

    The following works for one sheet:

    Option Explicit
    Sub auto_open()
    With Worksheets("REPORT1")
    .Protect Password:="test", userinterfaceonly:=True
    .EnableOutlining = True
    End With
    End Sub

    Can this be modified to work for three sheets in the same workbook?

    Thanks for you help.

    Gos-C

  6. #6
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Gos-C
    Hi Bryan,

    I noticed you suggested code has "AllowFormattingCells." Would that allow the outlining level symbols to work when the sheet is protected?

    The following works for one sheet:

    Option Explicit
    Sub auto_open()
    With Worksheets("REPORT1")
    .Protect Password:="test", userinterfaceonly:=True
    .EnableOutlining = True
    End With
    End Sub

    Can this be modified to work for three sheets in the same workbook?

    Thanks for you help.

    Gos-C
    Hi,

    yes, you need to amend

    With Worksheets("REPORT1")

    and set in a loop, thus

    dim ws as worksheet
    for each ws in worksheets
    ~~ code here
    next ws

    You may need to exclude some sheets, skip the code if .name = etc

    Let me know how you go.

    ---

  7. #7
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Thumbs up

    Thank you very much, Bryan.

    I entered:

    Option Explicit
    Sub auto_open()
    Dim ws As Worksheet
    For Each ws In Worksheets
    With ws 'Worksheets("REPORT1")
    .Protect Password:="test", UserInterfaceOnly:=True
    .EnableOutlining = True
    End With
    Next ws

    End Sub

    . . . and, it worked!

    Gos-C
    Last edited by Gos-C; 12-20-2006 at 05:41 PM.

  8. #8
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Gos-C
    Thank you very much, Bryan.

    I entered:

    Option Explicit
    Sub auto_open()
    Dim ws As Worksheet
    For Each ws In Worksheets
    With ws 'Worksheets("REPORT1")
    .Protect Password:="test", UserInterfaceOnly:=True
    .EnableOutlining = True
    End With
    Next ws

    End Sub

    . . . and, it worked!

    Gos-C
    Great to see a resolution, and thanks for the response.

    ---

+ 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