Duhwellhuh
New Member
- Joined
- Apr 15, 2012
- Messages
- 6
Hello everyone
This is my first post. I've spent all day trying to figure this one out. What I'm trying to do is check the existence of files in subdirectories by matching text in an excel range ("A:A"). The text within each cell in the excel range are partial filenames. So far, I've been using filesystem object and wild cards and a like statement within an if statement, but it doesn't work. Some files appear to be available, while others aren't. Any help would be truly appreciated, here's what I got:
This is my first post. I've spent all day trying to figure this one out. What I'm trying to do is check the existence of files in subdirectories by matching text in an excel range ("A:A"). The text within each cell in the excel range are partial filenames. So far, I've been using filesystem object and wild cards and a like statement within an if statement, but it doesn't work. Some files appear to be available, while others aren't. Any help would be truly appreciated, here's what I got:
Code:
Sub GetSubFiles()
Dim fso, fldr, subFldr, oFiles, oFile, myBaseName
Dim mySF, myName, strName As String
Dim myRange As Range
mySF = "G:\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder(mySF)
Set myRange = Sheets(2).Range("A:A")
For Each fn In myRange
For Each subFldr In fldr.SubFolders
Set oFiles = subFldr.Files
For Each oFile In oFiles
myName = fso.GetBaseName(oFile)
If fn.Value = "" Then
Exit Sub
Else
'Debug.Print fn.Value
If LCase("*" & fn.Value & "*") Like (LCase("*" & myName & "*")) Then
fn.Offset(0, 1).Value = "Available"
fn.Offset(0, 1).Interior.Color = RGB(0, 255, 0)
Else
fn.Offset(0, 1).Value = "Not Available"
fn.Offset(0, 1).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Debug.Print myName
Next
Next
Set oFiles = Nothing
Set subFldr = Nothing
Set fldr = Nothing
Set fso = Nothing
End Sub