Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Las Vegas, Nevada, USA
    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
    Dublin, Ireland, Republic of
    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= &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