sure. you have to set up that class module like i showed you before. Go to Tools > References and check "microsoft scripting runtime", then hit Insert > Class Module and name it clsFileHandler. Then paste this code into it.
Code:
'To use this class module in another workbook, you'll need to set a reference to the "microsoft scripting runtime" library
Option Explicit
Private FSO As Scripting.FileSystemObject
Private oMainFolder As Scripting.Folder
Private oFileCollection As Scripting.Files
Private oFile As Scripting.File
'For putting the file list into a worksheet
Private rgTarget As Range
Private lRangeRow As Long
Private lTargetOffset As Long
Public Sub GetAllFiles(FolderPath As String, Target As Range)
'gets all files in FolderPath, including those in subfolders
Static oParentFolder As Scripting.Folder
Static oSubFolder As Scripting.Folder
Static oFolders As Scripting.Folders
Set oParentFolder = FSO.GetFolder(FolderPath)
Set oFolders = oParentFolder.SubFolders
GetFileList FolderPath, Target
If oFolders.Count = 0 Then 'there's no subfolders in this folder
Exit Sub
End If
For Each oSubFolder In oFolders
GetFileList oSubFolder.Path, Target
GetAllFiles oSubFolder.Path, Target
Next
End Sub
Public Sub ClearPreviousSearch(shtSheet As Worksheet)
shtSheet.UsedRange.EntireRow.Delete
lTargetOffset = 0
End Sub
Public Sub GetFileList(FolderToSearch As String, Target As Range)
'this will put a list of files on a spreadsheet at the Target, does not include files in subfolders
'Put a trailing backslash on path if it's not there
If Right(FolderToSearch, 1) <> "\" Then
FolderToSearch = FolderToSearch & "\"
End If
Set rgTarget = Target
Set oMainFolder = FSO.GetFolder(FolderToSearch)
Set oFileCollection = oMainFolder.Files
lRangeRow = Target.Row
For Each oFile In oFileCollection
If Not InStr(CStr(oFile.Name), "b") Then
Target.Offset(lTargetOffset, 0) = oFile.Path
Target.Offset(lTargetOffset, 1) = oFile.Name
lTargetOffset = lTargetOffset + 1
End If
Next oFile
End Sub
Private Sub Class_Initialize()
Set FSO = New Scripting.FileSystemObject
End Sub
Private Sub Class_Terminate()
Set FSO = Nothing
End Sub
then in your regular code Module put this in the declarations:
Code:
Dim FH As New clsFileHandler
we'll have to switch the code around some to get it to do what you want, so lemme know when you're online