Hi there,
You might be able to use something like this ...
Sub LoopThroughFolder()
Dim FSO As Object, fsoFolder As Object, fsoFile As Object
Dim wb As Workbook, blnOpened As Boolean, strFolderPath As String
strFolderPath = "C:\Users\Zack\Documents\Dashboard Kits"
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(strFolderPath) Then
MsgBox "The specified folder '" & strFolderPath & "' does not
exist!", vbCritical, "ERROR!"
Exit Sub
End If
Set fsoFolder = FSO.GetFolder(strFolderPath)
For Each fsoFile In fsoFolder.Files
If InStr(1, fsoFile.Type, "Excel") = 0 Then GoTo SkipFile
If WbOpen(fsoFile.Name) = False Then
Set wb = Workbooks.Open(fsoFile.Path)
blnOpened = True
Else
Set wb = Workbooks(fsoFile.Name)
blnOpened = False
End If
Call YourCodeHere(wb) 'the workbook passed as a variable
If blnOpened = True Then
wb.Close savechanges:=False 'True
End If
Set wb = Nothing
SkipFile:
Next fsoFile
End Sub
Function WbOpen(wbName As String) As Boolean
On Error Resume Next
WbOpen = Len(Workbooks(wbName).Name)
End Function
Sub YourCodeHere(ByVal wkb As Workbook)
MsgBox "The workbook being worked on is '" & wkb.Name & "'.",
vbInformation, "INFORMATION"
End Sub
HTH
--
Regards,
Zack Barresse, aka firefytr
MsgBox "fire" & "fytr" & Chr(64) & "vba" & "express" & Chr(46) & "com"
"open a adobe file from a command button"
<(E-Mail Removed)> wrote in
message news

951E85A-4138-4697-9D3F-(E-Mail Removed)...
>I have a some code that cleans up a Excel spreadsheet very well. Now I
>have
> 20 or 25 spreadsheets that are formatted the same way and I want to clean
> them up. How would I go about having this code ran on all the
> spreadsheets
> in a directory? Do I have to do them one at a time?
>
> Thanks
>