+ Reply to Thread
Results 1 to 4 of 4

what is wrong with this code? (enable rowformatting and outlining in protected sheets )

  1. #1
    Registered User
    Join Date
    04-26-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    5

    Exclamation what is wrong with this code? (enable rowformatting and outlining in protected sheets )

    Simply trying to enable both the formatting options as well as the expand / collapse option for a locked and protected workbook which has a few tabs in it. It seems to work when I run it .. but when I close and open the work book only the formatting works and the expand/collapse does not work.. Any help is greatly appreciated.. as I am not good at Excel coding :P

    Private Sub Format_Workbook()
    Dim wks As Worksheet
    Dim wkbk As Workbook

    Set wkbk = ActiveWorkbook

    For Each wks In wkbk.Worksheets
    wks.Unprotect Password:="exceltemplate"
    wks.Cells.Locked = False

    Select Case (wks.Name)
    Case "Sheet1", "Sheet2", "Sheet3", "Sheet4"
    With wks
    .Protect Password:="exceltemplate", UserInterfaceOnly:=True
    .EnableOutlining = True
    End With
    Case Else
    End Select
    On Error Resume Next
    wks.UsedRange.SpecialCells(xlCellTypeFormulas).Locked = True
    On Error GoTo 0

    wks.Protect Password:="exceltemplate", AllowFormattingCells:=True, _
    AllowFormattingColumns:=True, AllowFormattingRows:=True, _
    AllowInsertingColumns:=True, AllowInsertingRows:=True

    Next wks

    End Sub

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: what is wrong with this code? (enable rowformatting and outlining in protected sheets

    in order for outlines to work you need to protect using userinterfaceonly:=true but that setting is not saved with the workbook so you need to reset it each time the workbook is opened
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    04-26-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: what is wrong with this code? (enable rowformatting and outlining in protected sheets

    Thank you for your reply So you mean, I will have to run the code everytime i open the work book for it to work? There is no other way to make it work?
    The reason I am doing it is because, i had the macro for the expand/collapse function alone which worked fine, but ever since I put in macro it seems to be messing with the checks I put against the formatting, insert row, insert column, delete row options before you protect the sheet... this keeps resetting everytime i open and close the workbook..

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: what is wrong with this code? (enable rowformatting and outlining in protected sheets

    You can call your routine from the workbook_open event so that it runs automatically when the workbook is opened

+ 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