+ Reply to Thread
Results 1 to 13 of 13

FIXED - MAcro to protect/unprotect sheets based on password in cell

  1. #1
    Registered User
    Join Date
    12-08-2011
    Location
    Livertpool
    MS-Off Ver
    Excel 2010
    Posts
    12

    FIXED - MAcro to protect/unprotect sheets based on password in cell

    Hi,

    I have a lovely macro which protects all of my sheets (even asks me nicely if i want to protect each individual sheet) and a unprotect one too.

    However these are useless as others can press these buttons and edit my spreadsheets. They need to view the spreadsheet but i need to protect from sticky fingers...

    I would protect the sheets manually or leave the unprotect macro out of it but i have a LOT of sheets i need to work with... takes ages doing it the manual way.

    So what i would like to do is protect or unprotect ALL sheets based on what text appears in a certain cell, for example:

    Cell A1 has "password" in it, i press lock all sheets button and all sheets are now locked
    Cell A1 has nothing in it, i press lock all sheets button and a warning message appears saying wrong password

    And vice versa for the unprotect part..

    Can anyone help?
    Last edited by pmcook1979; 01-10-2012 at 04:28 AM.

  2. #2
    Registered User
    Join Date
    12-08-2011
    Location
    Livertpool
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: MAcro to protect/unprotect sheets based on password in cell

    ANyone able to help?

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: MAcro to protect/unprotect sheets based on password in cell

    It will be good if you attach your macro file here. I feel it requires some minor changes.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    12-08-2011
    Location
    Livertpool
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: MAcro to protect/unprotect sheets based on password in cell

    Ok -

    Sub Protect_Example2()

    ' Loop through all sheets in the workbook
    For i = 1 To Sheets.Count

    ' Activate each sheet in turn.
    Sheets(i).Activate

    response = MsgBox("Do you want to protect this sheet?", vbYesNo)
    If response = vbYes Then
    ActiveSheet.Protect Password:="larry", DrawingObjects:=True, _
    Contents:=True, Scenarios:=True

    ElseIf response = vbNo Then
    MsgBox ("Sheet not protected")

    End If
    Next i
    End Sub


    Again i would like this to point to a cell i state and that cell must contact the password set in the VB code... thanks!

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: MAcro to protect/unprotect sheets based on password in cell

    How do you plan to state the cell? Do you want a msgbox asking for the cell address?

  6. #6
    Registered User
    Join Date
    12-08-2011
    Location
    Livertpool
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: MAcro to protect/unprotect sheets based on password in cell

    It will be a cell that the macro automatically points to that i have chosen (A1 for now).

    It would automatically check the text in that cell and see if it matches before locking/unlocking...

  7. #7
    Registered User
    Join Date
    12-08-2011
    Location
    Livertpool
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: MAcro to protect/unprotect sheets based on password in cell

    Hi, Anyone had the time to help with the below below please?

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: MAcro to protect/unprotect sheets based on password in cell

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  9. #9
    Registered User
    Join Date
    12-08-2011
    Location
    Livertpool
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: MAcro to protect/unprotect sheets based on password in cell

    Please Login or Register  to view this content.

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: MAcro to protect/unprotect sheets based on password in cell

    Maybe something like this

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-08-2011
    Location
    Livertpool
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: MAcro to protect/unprotect sheets based on password in cell

    Thanks, it works perfectly for protecting all the sheets and prompting for the password but...

    Could it be reversed to unlock them all too, prompting for a password (the one used to lock it)?

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: MAcro to protect/unprotect sheets based on password in cell

    You only need to cahnge if to UnProtect, or you could have a procedure that you call & define what you want to do

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    12-08-2011
    Location
    Livertpool
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: MAcro to protect/unprotect sheets based on password in cell

    Perfect! Thanks very much!!

+ 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