+ Reply to Thread
Results 1 to 10 of 10

Macro to Unprotect and Protect

Hybrid View

  1. #1
    Registered User
    Join Date
    05-16-2013
    Location
    Chiang Mai, Thailand
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Macro to Unprotect and Protect

    Hi,

    I am having a similar problem but I am not clear if the code applies to my situation or where I would insert the code into my existing macro.

    My situation is that I also want to protect my worksheet so that staff don't unwittingly alter codes and values; however, the sheet also has a macro that allows users to select more than one option for one cell. If I protect the worksheet, the macro won't work.

    How can I use the macro AND protect the worksheet?

    Thanks,
    Lyndy

    Quote Originally Posted by HaHoBe View Post
    Hi, MBeedle,

    you may pass the password when protecting and unprotecting the sheet. Please try and alter your password as needed:
    Sub unlockrefreshsearchsortlock()
    '
    ' unlockrefreshsearchsortlock Macro
    '
    
    '
        ActiveSheet.Unprotect Password:="PW"
        Application.Run "'RSA Agent List - Test.xlsm'!RefreshAndSearch"
        Range("Table_owssvr_2[[RSA LastName]:[Retailer]]").Select
        ActiveWorkbook.Worksheets("owssvr(1)").ListObjects("Table_owssvr_2").Sort. _
            SortFields.Clear
        ActiveWorkbook.Worksheets("owssvr(1)").ListObjects("Table_owssvr_2").Sort. _
            SortFields.Add Key:=Range("Table_owssvr_2[RSA LastName]"), SortOn:= _
            xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("owssvr(1)").ListObjects("Table_owssvr_2").Sort. _
            SortFields.Add Key:=Range("Table_owssvr_2[RSA FirstName]"), SortOn:= _
            xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("owssvr(1)").ListObjects("Table_owssvr_2").Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("Table_owssvr_2[[#Headers],[RSA LastName]]").Select
        ActiveSheet.Protect Password:="PW", DrawingObjects:=True, Contents:=True, Scenarios:=True
    End Sub
    I think the code may be worked on to simplify it a bit.

    Ciao,
    Holger

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to Unprotect and Protect

    Hi, lyndy256,

    see my answer in http://www.excelforum.com/showthread...=1#post3248665.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ 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