This is a bit odd, I'm sure it used to work but seems not now. Its meant to get all folders from a given path. Plus their subfolders if DoDepths is True, but it's not. A bug exists as DoDepths is True, even if False. I suspect Optional is used incorrectly.
Perhaps someone could tell me where I'm going wrong ? Thanks.
Perhaps someone could tell me where I'm going wrong ? Thanks.
Code:
Function gFindFolders(ByVal findWhere As String, ByRef ErrNum As Integer, Optional DoAllDepths As Boolean = True) As Variant
On Error GoTo err_getFolder
Dim fso As Object, folder1 As Object, fNames As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder1 = fso.GetFolder(findWhere)
ThegFolders folder1, DoAllDepths, fNames
gFindFolders = Split(fNames, Chr$(255))
Set folder1 = Nothing
Set fso = Nothing
On Error GoTo 0
Exit Function
err_getFolder:
ErrNum = Err
End Function
Public Sub ThegFolders(ByRef gFolders As Object, DoDepths, ByRef Names)
Dim SubFolder As Object
Dim subfld As Object
For Each SubFolder In gFolders.SubFolders
Names = Names & Chr$(255) & SubFolder.Path
Next SubFolder
If DoDepths = True Then
For Each subfld In gFolders.SubFolders
ThegFolders subfld, True, Names
Next subfld
End If
End Sub