Code:
Public Function FileFolderExists(strFullPath As String) As String
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Check if a file or folder exists
On Error GoTo EarlyExit
FileFolderExists = Dir(strFullPath, vbDirectory)
EarlyExit:
On Error GoTo 0
End Function
Public Sub TestFolderExistence()
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Test if directory exists
Dim MyValue As String
Dim subFldr As Object
Dim msg As String
Dim fldr As String
MyValue = Range("B2").Value
ChDir "C:\"
fldr = FileFolderExists("C:\*" & MyValue & "*")
If fldr <> "" Then
For Each subFldr In CreateObject("Scripting.FileSystemobject").GetFolder(fldr).Subfolders
msg = msg & subFldr.Name & vbNewLine
Next subFldr
MsgBox msg, vbOKOnly, "All folders"
Else
MsgBox "Folder does not exist!"
End If
End Sub
Note that I havce changed both procedures.
Bookmarks