Hi Mark,
Here is your code modified so it gets the workbook names and passwords from the List.xlsx file and then opens and closes each password protected workbook. Instead of keeping the "List.xlsx" file open and reading from it while opening each workbook, the code below opens "List.xlsx", populates arrays for the workbook names and passwords, closes "List.xlsx" and then runs through another loop to deal with the password protected workbooks.
Sub updateme()
Dim myFileNames() As String
Dim myPasswords() As String
Dim myRealWkbkName As String
Dim LastRowA1 As Long
Dim LastRowB1 As Long
Dim PWWorkbook As Workbook
Dim SourceWorkbook As Workbook
Dim WorkbookPath As String
Dim i As Integer
Dim LastRow As Long
Dim LastColumn As Long
Dim rng As Range
' Turn OFF events
Application.ScreenUpdating = False
WorkbookPath = "C:\!!!!Users\wfh309\Desktop\New Log Setup\January 2016\Case Review Logs\"
myRealWkbkName = WorkbookPath & "List.xlsx"
' Open List.xlsx and retrieve reference workbook names and passwords
Workbooks.Open myRealWkbkName, UpdateLinks:=False
Set PWWorkbook = ActiveWorkbook
' Verify list of workbook names is same length as list of corresponding passwords
LastRowA1 = PWWorkbook.Sheets("List").[A1].End(xlDown).Row
LastRowB1 = PWWorkbook.Sheets("List").[B1].End(xlDown).Row
If LastRowA1 <> LastRowB1 Then
MsgBox "check names & passwords--qty mismatch!"
Exit Sub
End If
' Populate wkbName() and wkbPass() arrays from List.xlsx
ReDim myFileNames(1 To LastRowA1) As String
ReDim myPasswords(1 To LastRowA1) As String
For i = 1 To LastRowA1
myFileNames(i) = PWWorkbook.Sheets(1).Cells(i, 1).Value
myPasswords(i) = PWWorkbook.Sheets(1).Cells(i, 2).Value
Next i
PWWorkbook.Close False
' Open Password Protected Workbooks, Execute code and close workbook
For i = 1 To LastRowA1
Workbooks.Open WorkbookPath & myFileNames(i), UpdateLinks:=False, Password:=myPasswords(i)
' < CODE HERE >
Workbooks(myFileNames(i)).Close SaveChanges:=False
Next i
' Turn ON events
Application.ScreenUpdating = True
End Sub
Hope that helps,
Dan
Bookmarks