Hello,
I am trying to check if a folder exists in a directory. I found some great code that does this if you already have the full path. I would like to check if a folder exists who's name contains specific numbers. Is there anyway to modify this existing code to check if a folder exists that contains a specific number? Instead of listing the full path in column A I wanted to list the specific numbers I am looking for. Once found and if possible I also need the full folder name printed on the next adjacent column (c). Any help would be great!
Public Function FileFolderExists(strFullPath As String) As Boolean
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Check if a file or folder exists
If Not Dir(strFullPath, vbDirectory) = vbNullString Then
FileFolderExists = True
Else
FileFolderExists = False
End If
End Function
Sub Macro1()
For Each Cell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
If IsEmpty(Cell) = True Then
Cell.Offset(0, 1).Value = "No suggested directory has been entered into " & Cell.Address(False, False)
ElseIf FileFolderExists(Cell.Value) = True Then
Cell.Offset(0, 1).Value = "Folder Exists"
Else
Cell.Offset(0, 1).Value = "Folder Does Not Exist"
End If
Next Cell
End Sub
Bookmarks