Encrypt Password In VBA

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Encrypt Password In VBA

Post by jstevens »

Is it possible to encrypt a password in Excel 2003 VBA? In the example below, the word "password" would be encrypted.

Example:

Code: Select all

Global Const pwProtect = "password"

ThisWorkBook.Sheets("MySheet").Protect Password:=pwProtect
Thanks,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Encrypt Password In VBA

Post by HansV »

You can't encrypt the password itself, but you can lock the VBA project for viewing:
- Activate the Visual Basic Editor (if necessary).
- Select Tools | VBAProject Properties... (the name VBAProject might be different, if you have changed it).
- Activate the Protection tab.
- Tick the check box "Lock project for viewing".
- Enter a password in both boxes.
- Click OK.
- Save the workbook.

To see the effect, quit and restart Excel. When you open the workbook and want to view the VBA code, you'll have to provide the password.
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Encrypt Password In VBA

Post by jstevens »

Hans,

Thank you for the suggestion.

Regards,
John
Regards,
John