+ Reply to Thread
Results 1 to 4 of 4

macro

  1. #1
    Forum Contributor
    Join Date
    05-04-2005
    Posts
    136

    macro

    I know how to tell a macro to protect and unprotect a sheet.
    is there a way that i can tell it to protect and unprotect and specify a password?

    activesheet.protect or will protect it but no password.

    thanks in advance

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon tkaplan

    Try this code

    ActiveSheet.Protect Password:="my_pass"
    ActiveSheet.Unprotect Password:="my_pass"

    HTH

    DominicB

  3. #3
    Forum Contributor
    Join Date
    05-04-2005
    Posts
    136
    Thank you.
    this worked to put a password over the protection but then if i want to manually go and unprotect it it tells me i have the wrong password.
    if i write a macro to go and unprotect everything that works but i want to just unprotect what i need manually by going to tool/protection and putting in the password.

    caps was not on but i tried doing capitals also and that didnt work either.

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi tkaplan

    Ok, two things.

    First I used and tested the macros below to destruction using them to protect sheets and unprotect manually, manually protect and unprotect using the macro, and using them interchanged and cannot recreate the problem you are reporting. I am using WinXP and Excel 2003.

    Sub protect()
    ActiveSheet.protect Password:="my_pass"
    End Sub
    Sub unprotect()
    ActiveSheet.unprotect Password:="my_pass"
    End Sub

    Secondly, I'm not sure what you mean by unprotect everything - do you mean every sheet, or every cell. If you mean every cell you need to change the protection status - alt +1, protection,check / uncheck the locked box. You can do it from VBA thus:

    Range("A1").Locked = False
    Range("A1").Locked = True

    HTH

    DominicB

+ 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