+ Reply to Thread
Results 1 to 2 of 2

ActiveWorkbook.Unprotect (prompt for password)

Hybrid View

  1. #1
    Registered User
    Join Date
    08-19-2004
    Posts
    60

    ActiveWorkbook.Unprotect (prompt for password)

    Hi all,

    i have a workbook and i want to run a macro to unprotect the workbook by prompting for a password first.

    Now if i want to prompt the user for a password and then unprotect the SHEET then using the following is fine:

    ActiveSheet.Unprotect
    However when i use:

    ActiveWorkbook.Unprotect
    i get an runtime error that the password supplied is incorrect (even though i haven't supplied one).

    Does anyone know how to get a password prompt there?

    Thanks

    James

  2. #2
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hi jamesryan,

    The code to unprotect a passworded sheet is as following:

    Sheets("Sheet Name").Unprotect "Password Here"
    'Or (in your case)
    ActiveSheet.Unprotect "Password Here"
    to prompt for the user to enter a password you can do this:

    Dim pwd As String
    
    pwd = InputBox("Please enter the password:")
    
    On Error GoTo WrongPW
    ActiveSheet.Unprotect pwd
    
    Exit Sub
    WrongPW:
    MsgBox ("The password is incorrect")
    There are only 10 types of people in the world:
    Those who understand binary, and those who don't!

+ 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