+ Reply to Thread
Results 1 to 7 of 7

Unprotect > Run Loop > Protect

  1. #1
    Registered User
    Join Date
    11-23-2013
    Location
    new york, ny
    MS-Off Ver
    Excel 2010
    Posts
    42

    Unprotect > Run Loop > Protect

    I have a macro that runs a loop on most sheets to clear colored cells. All worksheets are protected and I can't seem to integrate my protect and unprotect macros (which work!) into the clearing macro. Here are all 3:


    Clear cells
    Please Login or Register  to view this content.

    Unprotect all sheets

    Please Login or Register  to view this content.

    Protect all sheets


    Please Login or Register  to view this content.

    How can I integrate the 1. unprotect all sheets, 2. run clear macro, and 3. protect all sheets?

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Unprotect > Run Loop > Protect

    One of the parameters for the Protect command is: UserInterfaceOnly

    By setting that to TRUE, protection only applies to user activities...not VBA activities.
    Consequently, you will not need to unprotect the worksheets to have VBA do your clean-up routines.

    In your sample, try this:
    Please Login or Register  to view this content.

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    11-23-2013
    Location
    new york, ny
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Unprotect > Run Loop > Protect

    Thanks! That works!

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Unprotect > Run Loop > Protect

    Glad you got something you can use!

    If that resolves your issue, please take a moment to mark this thread as SOLVED (from the Thread Tools menu)

  5. #5
    Registered User
    Join Date
    11-23-2013
    Location
    new york, ny
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Unprotect > Run Loop > Protect

    Hi again, Ron. Thanks for your help... I'm experiencing an odd reaction to your solution. Sometimes, seemingly only when the workbook is opened (and was previously protected).


    Your solution works when I protect the sheets and then try to run the clear while its protected. But NOT when the sheet was protected, then closed, then opened, and then clear attempted to run...

    Hope that makes sense...

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Unprotect > Run Loop > Protect

    If the VBA code protected it before the close...I half-expected that the setting would remain when opened. But, maybe not. Experiment and let us know. You may need to have a Worksheet_Open macro that applies the protection.

  7. #7
    Registered User
    Join Date
    11-23-2013
    Location
    new york, ny
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Unprotect > Run Loop > Protect

    This does not work as a solution... Can someone help me integrate the unprotect, code, then protect macros?

+ 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] Protect / unprotect
    By MIGARDEIN in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2015, 04:17 PM
  2. VBA protect and unprotect
    By NotSwank in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2014, 02:11 PM
  3. Excel 2007 : protect and unprotect
    By runball in forum Excel General
    Replies: 0
    Last Post: 09-07-2009, 10:03 AM
  4. Protect UserInterface VS Protect/Unprotect
    By Desert Piranha in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2006, 11:08 PM
  5. protect and unprotect
    By Andrew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2005, 03: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