+ Reply to Thread
Results 1 to 9 of 9

All sheet: read-only protection

Hybrid View

  1. #1
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Exclamation All sheet: read-only protection

    Hello,

    I have gone through the various password protection methods but I can't get the workbook to do what I want.

    I want to make sure every tab is read-only and any accidental modification requires a password.

    "Protect sheet" protects the current sheet and I don't want to use a separate password for every tab. "Protect workbook" requires a password before it is opened.

    Any ideas?

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

    Re: All sheet: read-only protection

    You have to protect the sheet individually. You can automate this with a macro
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: All sheet: read-only protection

    Something like this:

    Sub Protect_Sheets()
    
    Dim strPWord As String
    Dim wsEachSheet As Worksheet
    
    strPWord = InputBox("Enter password to lock sheets")
    
    For Each wsEachSheet In ThisWorkbook.Worksheets
        wsEachSheet.Protect strPWord
    Next wsEachSheet
    
    End Sub
    
    Sub Unprotect_Sheets()
    
    Dim strPWord As String
    Dim wsEachSheet As Worksheet
    
    strPWord = InputBox("Enter password to unlock sheets")
    
    On Error GoTo ErrorHandler
    
    For Each wsEachSheet In ThisWorkbook.Worksheets
        wsEachSheet.Unprotect strPWord
    Next wsEachSheet
    
    CleanExit:
    Exit Sub
    
    ErrorHandler:
    MsgBox Err.Description
    GoTo CleanExit
    
    End Sub

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: All sheet: read-only protection

    Clever but the slight drawback is that there is no way to know if the password can be checked when unprotecting the worksheet so I am storing the string on a spreadsheet using the protect code and then I want to compare the string in the unprotect code.

    For some reason my If statement isn't working.

    Dim strPWord As String
    Dim wsEachSheet As Worksheet
    
    On Error GoTo ErrorHandler
    
    If Worksheets("Sheet1").Range("O4").Value <> strPWord Then Exit Sub
    
    Else
    
    For Each wsEachSheet In ThisWorkbook.Worksheets
        wsEachSheet.Unprotect strPWord
    Next wsEachSheet
    
    End If
    
    MsgBox "Worksheets unprotected"
    
    Unload UserForm2
    
    Unload UserForm1
    
    
    CleanExit:
    Exit Sub
    
    ErrorHandler:
    MsgBox Err.Description
    GoTo CleanExit
    Last edited by scubadiver007; 11-01-2011 at 12:25 PM. Reason: Clarification

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: All sheet: read-only protection

    Sorry, don't follow what you mean.

    Dom

  6. #6
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: All sheet: read-only protection

    I have created a password using the protect code but I have tried a completely different string of characters to unprotect the sheets and it works.

  7. #7
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: All sheet: read-only protection

    Are you sure? If the sheets were protected with a password after you ran the Protect_Sheets code there's no way the other code would unprotect them without the correct password even with Excel 2003's slack security.

    Dom

  8. #8
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: All sheet: read-only protection

    Sorry, might be my mistake. I'm not using an input box.

    EDIT: its fine now, thanks.
    Last edited by scubadiver007; 11-01-2011 at 12:33 PM.

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

    Re: All sheet: read-only protection

    Where does your code actually set a value to strPWord?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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