'Written: May 24, 2010
'Author: Leith Ross
Sub UpdateAll()
Dim Cell As Range
Dim Data() As Variant
Dim Passwords As Object
Dim Rng As Range
Dim RngEnd As Range
Dim Wkb As Workbook
Dim WkbName As String
On Error GoTo ErrorHandler
If ActiveSheet.Name = "Passwords" Then
MsgBox "You Can Not Run the Macro on this Worksheet."
Exit Sub
End If
Set Rng = Range("A3")
Set RngEnd = Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Or Rng.Cells(1, 1) = "" Then
MsgBox "There is no data on '" & ActiveSheet.Name & "'", vbOKOnly + vbExclamation
Exit Sub
Else
Set Rng = Range(Rng, RngEnd)
End If
Application.ScreenUpdating = False
Set Passwords = CreateObject("Scripting.Dictionary")
Passwords.CompareMode = vbTextCompare
For Each Cell In Worksheets("Passwords").Range("A1").CurrentRegion.Columns(1).Cells
If Not Passwords.Exists(Cell.Text) Then
Passwords.Add Cell.Text, Cell.Offset(0, 1).Text
End If
Next Cell
For Each Cell In Rng
WkbName = Join(Split(Cell.Text, " "), "_") & "_stats.xls"
Set Wkb = Workbooks.Open(Filename:=WkbName, Password:=Passwords(WkbName))
With Wkb.Worksheets("Summary")
Data = Array(.Cells(16, "C"), .Cells(16, "D"), .Cells(16, "E"), _
.Cells(16, "F"), .Cells(16, "G"), .Cells(16, "H"), _
.Cells(16, "I"), .Cells(16, "J"), .Cells(16, "M"), _
.Cells(16, "N"), .Cells(16, "O"), .Cells(16, "Q"), _
.Cells(16, "R"), .Cells(16, "S"), .Cells(16, "W"))
End With
Wkb.Close SaveChanges:=False
Rng.Offset(0, 1) = Format(Now(), "shortdate")
Rng.Offset(0, 2).Resize(1, UBound(Data) + 1).Value = Data
Next Cell
ErrorHandler:
Set Passwords = Nothing
Application.ScreenUpdating = True
MsgBox "Run-time error '" & Err.Number & "':" & vbCrLf & vbCrLf & Err.Description
End Sub
Bookmarks