View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
John John is offline
external usenet poster
 
Posts: 2,069
Default Macro to Insert Unique Password for Multiple Excel Files

not tested but following may do what you want.
code assumes that File name is in Col A with full path eg
C:\mydirectory\Filename.xls and password in Col B
but you can change code as required.

Sub SaveFilesWithPassword()
Dim FName As String
Dim Passwrd As String
Dim FListWs As Worksheet
Dim MyBook As Workbook


Set FListWs = Worksheets("Sheet1") '<<change as required

Application.DisplayAlerts = False

With FListWs

i = 1
Do While .Cells(i, 1).Value < ""

FName = .Cells(i, 1).Value
Passwrd = .Cells(i, 2).Value

Set MyBook = Workbooks.Open(FName)

With MyBook

.SaveAs Filename:=FName, Password:=Passwrd

.Close False

End With

Loop

End With

Application.DisplayAlerts = True

End Sub

--
jb


"ScottMsp" wrote:

Hello,

I have 200+ Excel files that I need to password protect with a unique
password for each file. I have the passwords prepared, I am not sure how to
write the macro to look at a list and set the password for each file to the
unique password I have assigned to it.

Thanks in advance.