macro to password protect exel file

G

Guest

Hi,
I need to password protect hundreds of exel files with the same password,
but my boss wants them done one by one (as opposed to a zip file). The files
are in different directories and have different names. Can I create a macro
that will do the following once I have the file open?
Go to Save As
Go to Tools
Select General Options
Enter password to protect (i.e. 1234)
click OK
Retype password
Click OK
Save

I have been doing this for the past hour one file at a time and my fingers
are really tired now. Any help is GREATLY appreciated.
 
T

Tom Ogilvy

Look at help on the Workbook.SaveAs command. Password is one of the
arguments.

Sub PasswordFiles()
Dim sFname as String, sPath as String
sPath = "C:\My Folder\"

sFname = Dir(sPath & "*.xls")
do While sFname <> ""
Workbooks.Open sPath & sFname

Application.DisplayAlerts = False
ActiveWorkbook.Saves FileName:=ActiveWorkbook.fullname, _
FileFormat:=xlWorkbookNormal, Password:="1234"
Application.DisplayAlerts = True
ActiveWorkbook.Close SaveChanges:=False
sFname = Dir()
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top