PDA

View Full Version : password protection



MrYemin09
12-30-2009, 07:46 AM
Hello,
How can create VBA code for password protection for (.xls file).
When excel file ,ask for password box show and enter password and open.
Please help me! Thanks!

Aflatoon
12-30-2009, 07:49 AM
If I understand your question correctly, you do not need code for this. Choose Save As from the Office menu, then in the Save dialog, choose Tools-General options and set a password to open the file.

MrYemin09
01-01-2010, 04:16 AM
Thanks !
I know this action. I want to know how to write vba code for password protection.

very thanks Aflatoon.

GTO
01-01-2010, 06:27 AM
Greetings,

Try:

Sub exa()
Const PWD As String = "YourPasswordHere"

Application.DisplayAlerts = False

ThisWorkbook.SaveAs Filename:=ThisWorkbook.FullName, _
FileFormat:=xlNormal, _
Password:=PWD

Application.DisplayAlerts = True

End Sub


Hope that helps,

Mark