+ Reply to Thread
Results 1 to 4 of 4

Protecting every sheet and not allowing to select locked or unlocked cells

Hybrid View

  1. #1
    Registered User
    Join Date
    06-09-2011
    Location
    St louis, mo
    MS-Off Ver
    Excel 2007
    Posts
    33

    Protecting every sheet and not allowing to select locked or unlocked cells

    I have a workbook with about 50 sheets in it. I need to be able to protect all the sheets but also don't want the user selecting locked or unlocked cells. Below is the code that I have pieced together from other searching. Right now it is protecting the sheets but doesn't prompt for a password when un-protecting it. It also doesn't let you select but will have the cells highlighted from when it was saved. Thanks for any input and if you could also give code for unlocking the entire workbook at one time that would be appreciated.

    
    Sub Protect_sheets()
     
        Dim wSheet          As Worksheet
        Dim Pwd             As String
     
        Pwd = InputBox("Enter your password to protect all worksheets", "Password Input")
        For Each wSheet In Worksheets
            
        With wSheet
        .Protect
        .EnableSelection = xlUnlockedCells
        End With
            
        wSheet.Protect Password:=Pwd
        
        
        Next wSheet
     
    End Sub

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Protecting every sheet and not allowing to select locked or unlocked cells

    Try this:

    
    Sub Protect_sheets()
     
        Dim wSheet As Worksheet
        Dim Pwd As String
     
        Pwd = InputBox("Enter your password to protect all worksheets", "Password Input")
        For Each wSheet In Worksheets
            With wSheet
                .Protect Password:=Pwd
                .EnableSelection = xlNoSelection
            End With
        Next wSheet
     
    End Sub
    
    Sub UnProtect_sheets()
        Dim wSheet As Worksheet
        Dim Pwd As String
     
        Pwd = InputBox("Enter your password to unprotect all worksheets", "Password Input")
        For Each wSheet In Worksheets
            wSheet.Unprotect Password:=Pwd
        Next wSheet
    End Sub
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  3. #3
    Registered User
    Join Date
    06-09-2011
    Location
    St louis, mo
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Protecting every sheet and not allowing to select locked or unlocked cells

    Worked perfect. I added to your reputation. You rock.

  4. #4
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Protecting every sheet and not allowing to select locked or unlocked cells

    Thank you, im always happy to help out.

+ 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