+ Reply to Thread
Results 1 to 16 of 16

Issue with Protect/Unprotect Macro

  1. #1
    Registered User
    Join Date
    08-02-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Issue with Protect/Unprotect Macro

    I use the following protect/unprotect Macros in all of my files that need to be edited by multiple users. They work like a charm, except for the most recent file I have been working on.

    ____________________________________________
    Sub Protect()

    'stops screen updating

    Application.ScreenUpdating = False



    'protects locked cells

    For Each sht In ActiveWorkbook.Sheets
    sht.Protect Password:="teslinoor", DrawingObjects:=False, Contents:=True, Scenarios:= _
    True, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:= _
    True

    Next
    ActiveWorkbook.Protect Password:="teslinoor", Structure:=True


    End Sub
    _________________________________
    Sub Unprotect()

    'stops screen updating

    Application.ScreenUpdating = False



    'unprotects locked cells

    For Each sht In ActiveWorkbook.Sheets
    sht.Unprotect Password:="teslinoor"
    Next
    ActiveWorkbook.Unprotect Password:="teslinoor"

    End Sub
    ____________________________________________

    I keep getting the "Error 1004" Error that states, "The password you supplied is not correct. Verify that the CAPS LOCK key is off and be sure to use the correct capitalization."

    I have ensured that CAPS LOCKS is off (and I have even tried it with it on) and I have been careful to use the same capitalization. Additionally, when locked, this file needs to remain sortable.

    Any help would be apprecaited.

    -JT

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Issue with Protect/Unprotect Macro

    Caps lock wont matter in code, unless the password is in caps, but it looks the same.

    What is erroring the unprotect?
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    08-02-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Issue with Protect/Unprotect Macro

    Sub Unprotect()

    'stops screen updating

    Application.ScreenUpdating = False



    'unprotects locked cells

    For Each sht In ActiveWorkbook.Sheets
    sht.Unprotect Password:="teslinoor"
    Next
    ActiveWorkbook.Unprotect Password:="teslinoor"

    End Sub

    "sht.Unprotect Password:="teslinoor" is the error. I have even tried manually unprotecting the file by typing in nthe password from the protect macro, but that has failed as well. Now my file is locked and I unable to unlock it for further editions.

    -JT

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Issue with Protect/Unprotect Macro

    Have you tried unprotecting the book 1st?

  5. #5
    Registered User
    Join Date
    08-02-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Issue with Protect/Unprotect Macro

    Yes, and the passowrd is not working for that either.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Issue with Protect/Unprotect Macro

    Have you tried to manually unprotect using CAPS? if you protected manually and had caps on then the password could accidentally be capitals. Caps on or off won't change what the macro enters, but will affect manual locks/unlocks
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  7. #7
    Registered User
    Join Date
    08-02-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Issue with Protect/Unprotect Macro

    CAPS were not a factor in any of the manul locks; I did not manually lock the file at all. CAPS were only included on my last resort, failed manual unlock attempts.

  8. #8
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Issue with Protect/Unprotect Macro

    can you attach the workbook then, so we can look.

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Issue with Protect/Unprotect Macro

    Here's a suggestion,

    insert the macro below, it will unlock the active sheet. It won't give you the real password, but it does use a backdoor password in excel, so your sheet will be unlocked, then you can work with the real password again.

    <code removed>
    Last edited by 6StringJazzer; 07-22-2014 at 11:16 AM. Reason: removed code to break security

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Issue with Protect/Unprotect Macro

    Arkadi, your post does not comply with Rule 11 of our Forum RULES.

    Don't post questions regarding breaking or bypassing any security measure. Such posts will be deleted, and repeat offenders will be banned. This includes posting of links to sites that offer software, code or services to do this or posting of code to remove passwords
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Issue with Protect/Unprotect Macro

    jtal, your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Issue with Protect/Unprotect Macro

    Quote Originally Posted by 6StringJazzer View Post
    Arkadi, your post does not comply with Rule 11 of our Forum RULES.

    Don't post questions regarding breaking or bypassing any security measure. Such posts will be deleted, and repeat offenders will be banned. This includes posting of links to sites that offer software, code or services to do this or posting of code to remove passwords
    Sorry, since this seemed legitimate use, it didn't occur to me (but should have, not defending the post, honest mistake)... my bad *appologies*

  13. #13
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Issue with Protect/Unprotect Macro

    I did not issue an infraction due to the context and your intent. I agree that you were acting in good faith trying to answer the question. But rules are rules and so we don't want the code published on this forum.

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Issue with Protect/Unprotect Macro

    Arkadi,

    When you joined the forum originally you agreed to abide by the Forum Rules, but your comments above lead me to fear you might not have actually read them. Please stop and take a moment to read them now. It will resolve all the issues that exist about things you don't know about our forum. We all follow these rules for the benefit of all, as must you. Thanks.

    (link above in the menu bar)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  15. #15
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Issue with Protect/Unprotect Macro

    Yes, JBeaucaire, as I mentioned earlier, given the intent, it never ocurred to me. I have read the rules, and do as a rule abide by them, we all make mistakes. Thanks.

    *EDIT* sorry that was snotty.... You guys do a fantastic job maintaining this forum, and I apologize for my oversight.
    Last edited by Arkadi; 07-23-2014 at 11:23 AM.

  16. #16
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Issue with Protect/Unprotect Macro

    Most people I make the comment above to admit the haven't read the rules. No worries, you are doing fine.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to Unprotect and Protect
    By MBeedle in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-22-2013, 01:32 AM
  2. [SOLVED] Protect / Unprotect Macro
    By jason.hampton in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-06-2012, 03:36 AM
  3. Protect & unprotect worksheet Macros - supplementary issue
    By David_S_Walker in forum Excel General
    Replies: 2
    Last Post: 03-31-2010, 07:35 AM
  4. Macro to Protect and UnProtect
    By mmacw in forum Excel General
    Replies: 2
    Last Post: 02-13-2007, 04:39 PM
  5. [SOLVED] unprotect and protect within a macro
    By Staalkop in forum Excel General
    Replies: 4
    Last Post: 10-27-2005, 04:05 PM

Tags for this Thread

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