+ Reply to Thread
Results 1 to 7 of 7

Worksheet Protection with password

  1. #1
    Registered User
    Join Date
    09-28-2010
    Location
    Illinois
    MS-Off Ver
    Excel 2010
    Posts
    12

    Worksheet Protection with password

    I have a spreadsheet that I have completed that everyone in the office shares.
    I can record a macro to protect and unprotect a specfic sheet, but i cannot get the macro to record protecting and unprotecting the sheet with a password.
    Is there code that can be written for that?
    Thank you,
    Todd
    Last edited by Bhawxfan; 03-12-2011 at 02:18 PM.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Worksheet Protection with password

    How about something like...

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    09-28-2010
    Location
    Illinois
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Worksheet Protection with password

    Please Login or Register  to view this content.
    'Standard Module
    Sub WSprotect()
    Dim MyPassword As String
    Dim ws As Worksheet
    MyPassword = _
    Application.InputBox(prompt:="Enter password to protect worksheets/workbook", _
    Title:="Password Input")
    For Each ws In Worksheets
    ws.Protect MyPassword, userinterfaceonly:=True Next ws
    ActiveWorkbook.Protect MyPassword
    End Sub
    Please Login or Register  to view this content.
    Jeff,
    I copied and pasted the above code, but get an error after entering password. Error 1004; the password you supplied is not correct. What am I doiong wrong or missing?
    Please and Thank you,
    Todd

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

    Re: Worksheet Protection with password

    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

  5. #5
    Registered User
    Join Date
    09-28-2010
    Location
    Illinois
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Worksheet Protection with password

    Jeff,
    The following code...
    Sub WSprotect()
    Dim MyPassword As String
    Dim ws As Worksheet
    MyPassword = _
    Application.InputBox(prompt:="Enter password to protect worksheets/workbook", _
    Title:="Password Input")
    For Each ws In Worksheets
    ws.Protect MyPassword, userinterfaceonly:=True
    Next ws
    ActiveWorkbook.Protect MyPassword
    End Sub
    Generates error 1004 "The password you supplied is incorrect".
    How can it be incorrect when I am just entering it? Am I missing some programming?
    Please and Thank You,
    Todd
    Last edited by Bhawxfan; 03-12-2011 at 01:16 PM.

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Worksheet Protection with password

    hi Bhawxfan,

    the code prvd. by Jeff works for me, see the file attached,
    john
    Attached Files Attached Files

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

    Re: Worksheet Protection with password

    You need to use Code Tags, not Quote Tags & edit the original post, don't confuse Thread readers by posting again

+ 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