Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Oct 2005
    Posts
    599
    Thanks
    1
    Thanked 1 Time in 1 Post

    Using a password in a macro (Excel 2003)

    I have a spreadsheet that I use for auto calculating expenses and totaling them. I also made a little macro (that is triggered by hitting a button) that will autofit row height and autofit column width (to expand a column if it displays ####). I have many of the cells locked to prevent accidental erasure of formulae. If I set up my macro with a password, it won't run (b/c it calls for the password) and I won't release the password b/c people will unlock the sheet and accidentally erase things.....is there any way to incorporate a password into my macro so that it will unprotect the sheet, run the autofit macro and re-protect the sheet (without requiring the use to manually enter the password)?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Using a password in a macro (Excel 2003)

    Yes:

    Worksheets("Sheet1").Unprotect Password:="topSecret"
    ...
    ...
    Worksheets("Sheet1").Protect Password:="topSecret"

    However, anyone who knows how to activate the Visual Basic Editor can read the macro code and see the password. To prevent this, you can set a password on the VBA project:
    - In the Visual Basic Editor, select Tools | VBAProject Properties...
    - Activate the Security tab.
    - Tick the check box "Lock the project for viewing".
    - Enter the password in both boxes.
    - Click OK.
    - Save the workbook.
    - Next time the workbook is opened, you'll need to provide the password to view and edit VBA code.
    - Don't lose this password!

  3. #3
    4 Star Lounger
    Join Date
    Oct 2005
    Posts
    599
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Using a password in a macro (Excel 2003)

    Thank you for that Hans...works like a charm!! Your knowledge is amazing..

Posting Permissions

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