Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Las Vegas, Nevada, USA
    Posts
    334
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Add Password Prodect/Unprotect to Macro

    I have recorded a brief to help modify and save my company's 104 departmental budget worksheets. But even though I enter a password two times while recording the macro, the code is not recorded.
    How does one add password protection within a macro, and then what code is used to within a macro to unprotect?

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Add Password Prodect/Unprotect to Macro

    The following snippet of code will protect all sheets in a workbook, where Pass is the actual password <pre> Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets
    ws.Protect Password:=Pass
    Next ws </pre>


    To unprotect just change ws.Protect to ws.Unprotect

    This code is very simplistic and contains no error checking (wrong password) etc. For a slightly more secure approach see <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=xl&Number=37514&page=&view= &sb=&vc=1>Here</A>

    Hope it helps

    Andrew C

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •