+ Reply to Thread
Results 1 to 7 of 7

Protecting all but one worksheet macro not working

Hybrid View

  1. #1
    Registered User
    Join Date
    04-03-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Protecting all but one worksheet macro not working

    I have a workbook that has a copy macro in it. At the end of the macro, it protects all of the worksheets. But I need to have one worksheet remain unprotected. I have seen several options on this site, but I keep getting a run-time error 424. Here is the code that I have that works:

    ' protect worksheet
    For Each sht In NewBook.Worksheets
    sht.Protect Password:="secret"
    Next



    MsgBox "Copy Complete", vbOKOnly, "Copy Complete"
    End Sub

    I have tried using case select (my worksheet name is called "instructions" but same issue. Any help would be appreciated.

    Thanks.

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Protecting all but one worksheet macro not working

    hi,
    maybe this
    For Each sht In NewBook.Worksheets
     sht.Protect Password:="secret"
     Next
    
     MsgBox "Copy Complete", vbOKOnly, "Copy Complete"
     Sheets("Sheet1").Unprotect Password:="secret"  'change the name...
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  3. #3
    Registered User
    Join Date
    04-03-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Protecting all but one worksheet macro not working

    Hi John:

    Thanks for the quick answer. It stopped the runtime error but now it protects the entire workbook. It just not not seem to be reading the unprotect code.

    Shauna

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Protecting all but one worksheet macro not working

    it works for me..
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    04-03-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Protecting all but one worksheet macro not working

    Hi John - I downloaded your worksheet and sees that it works. Since I only sent you part of the code I am wondering if there is something else that is overwriting this. I will start a new macro again to see if this works. Thanks for all you help - it's really appreciated, especially the quick responses.

    Shauna

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Protecting all but one worksheet macro not working

    hi Shauna,
    you're welcome!

  7. #7
    Registered User
    Join Date
    04-03-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Protecting all but one worksheet macro not working

    Hi John:

    Changed the code and it now 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