Macro to password protect several excel files in same folder

  • Thread starter Thread starter Joshua Fredrickson
  • Start date Start date
J

Joshua Fredrickson

I have a customer who would like to password protect every
excel file in a folder at once.

She will be getting about 30 files that she will need to
do this on every month.

Anyone have code to do this already?

Thanks,
Joshua
 
Hi Joshua,

This should do it. It opens all files, adds the password, then closes them

Sub ProcessFiles()
im sFolder As String
Dim fldr As Object
Dim Folder As Object
Dim file As Object
Dim Files As Object

Set FSO = CreateObject("Scripting.FileSystemObject")

Application.DisplayAlerts = False

sFolder = "C:\myTest"
If sFolder <> "" Then
Set Folder = FSO.GetFolder(sFolder)

Set Files = Folder.Files
For Each file In Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
ActiveWorkbook.SaveAs Filename:=file.Path, _
Password:="bob"
ActiveWorkbook.Close
End If
Next file

End If ' sFolder <> ""

Application.DisplayAlerts = True

End Sub



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Bob, I will give this a try. Thanks so much for your
response. You saved me a few hours of work I'm sure.

I really appreciate your immediate response.

Joshua
 

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

Back
Top