+ Reply to Thread
Results 1 to 6 of 6

Protect sheet button is not working

Hybrid View

  1. #1
    Registered User
    Join Date
    12-14-2010
    Location
    London , England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Question Protect sheet button is not working

    I have created a button with the below assigned macro so that when the button is clicked, the whole spreasheet freezes.
    This works with the below code but the issue is that anyone can click on the review tab and unprotect sheet. the worksheet will then unlock without requesting the password, whereas it requests the password without the macro.

    Is there a way to fix the code so that anyone clicking on "unprotect sheet" will be prompted to enter the password. Any help would be greatly appreciated.! Thanks very much!

    Sub ProtectSheet()
    
        ActiveCell.Cells.Select
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
        ActiveSheet.EnableSelection = xlNoSelection
    End Sub
    Last edited by Sophster; 03-23-2011 at 07:35 AM. Reason: add code tags

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Protect sheet button is not working

    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
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Protect sheet button is not working

    Hi

    Just add password to your code
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="Password"
    Change the word within the quotes for "Password" to a word of your choice (and one you can remember!!!)
    Last edited by pike; 03-23-2011 at 06:54 AM. Reason: add code tags
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  4. #4
    Registered User
    Join Date
    12-14-2010
    Location
    London , England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Protect sheet button is not working

    Thanks Pike and sorry for not using the code tags. I'm not usually using vba, but need to in this instance. Below is the code with the code tags. I hope this will help

     ActiveCell.Cells.Select
     ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
     ActiveSheet.EnableSelection = xlNoSelection
    Last edited by pike; 03-23-2011 at 06:52 AM.

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

    Re: Protect sheet button is not working

    You don't need to select the cells.
    Hope that helps.

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

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    12-14-2010
    Location
    London , England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Protect sheet button is not working

    Many thanks all for your precious help! It's very much appreciated! Will make sure to follow the rules next time for VBA queries.

+ 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