Automatically Protect/UnProtect All Worksheets

Tonight I want to automatically protect and unprotect all Microsoft Excel Worksheets in my Workbook with password, instead of doing it manually, I put these following Excel VBA macro code in my Workbook.

Public Sub ProtectAllSheets()

    Dim objSheet As Worksheet

    'Protecting all worksheets with password
    For Each objSheet In Worksheets
        If objSheet.ProtectContents = False Then objSheet.Protect "a@#&ladfl&^"
    Next objSheet

End Sub

Public Sub UnProtectAllSheets()

    Dim objSheet As Worksheet

    'UnProtecting all worksheets with password
    For Each objSheet In Worksheets
        If objSheet.ProtectContents = True Then objSheet.Unprotect "a@#&ladfl&^"
    Next objSheet

End Sub

We only need to call the procedure ProtectAllSheets to protect with password all Excel Worksheets in our Workbook, and calling UnProtectAllSheets will reversed the effect.

This entry was posted in Workbook and Worksheet and tagged , , , , , , , . Bookmark the permalink.

1,775 Responses to Automatically Protect/UnProtect All Worksheets

  1. Yoav says:

    Hi,

    Wouldn’t the password be plainly visible to anyone looking at the VB code? Doesn’t it defeat the purpose of having a password?

    I am trying to achieve something similar and came across your post in a search.

    Do you know whether it is possible to have the code pop-up a password box such that you will have to put in your password in order to un/protect the worksheets in a way that you will not have to write your password into the script?

    Cheers,

    Yoav

  2. Pingback: reverse mortgage pros and cons

  3. Pingback: reverse mortgage lender

  4. Pingback: deutsch connectors

  5. Pingback: debt collection agency

  6. Pingback: dating factory bonus

  7. Pingback: collection agency rates

  8. Pingback: Alternative Energy Projects

  9. Pingback: Domitila Escarcega

  10. Pingback: collection agency

  11. Pingback: Bollywood Bhangra

  12. Pingback: hair salon st catharines

  13. Pingback: easy crm

  14. Pingback: collection agency newsletter

  15. Pingback: buy backlinks

  16. Pingback: wedding photographer calgary

  17. Pingback: Wedding Photography

  18. Pingback: ??????????? 2012

  19. Pingback: Saints Comforter Set Sales

  20. Pingback: buy facebook fans

  21. Pingback: Erotiek Groothandel

  22. Pingback: Dofollow

  23. Pingback: Landscape Gardeners North London

  24. Pingback: footlocker coupon codes

  25. Pingback: Justin Bieber

  26. Pingback: juegos de niƱas

  27. Pingback: hsbc credit card payment

  28. Pingback: continue to the website

  29. Pingback: credit auto

  30. Pingback: assurance auto pas cher

  31. Pingback: prets personnels

  32. Pingback: tatuaggi maori

  33. Pingback: transunion

  34. Pingback: pedicure

  35. Pingback: learn internet marketing

  36. Pingback: refrigerator reviews

  37. Pingback: click here

  38. Pingback: pay per click

  39. Pingback: SEO Services

  40. Pingback: ??? ???

  41. Pingback: right here

  42. Pingback: europeana portal

  43. Pingback: Best Little Black Cocktail Dress

  44. Pingback: ????? ??????

  45. Pingback: promo code for amazon

  46. Pingback: fishing tackle

  47. Pingback: more info

  48. Pingback: ford new car warranty 2008

  49. Pingback: Document Solutions

  50. Pingback: Otis

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>