J
Jenny
Hi, I found this code (courtesy Greg Maxey a while ago). I get an error.
Is anyone able to help me get this running please? I am trying to learn how
to manipulate foldes/subfolders and so far it's not going well! Thank you.
Set oFld = fso.GetFolder("E:\")
'Runtime Error 13 Type Mismatch
Option Explicit
'Add reference to Microsoft Scripting Runtime
Dim fso As New FileSystemObject
Dim colFolders As New Collection
Sub Demo()
Dim oFld As Folder
Dim lngC As Long
Set oFld = fso.GetFolder("E:\TEST")
'Runtime Error 13 Type Mismatch
MsgBox "Do something with: " & oFld
CollectSubFolders oFld
If colFolders.Count > 0 Then
For lngC = 1 To colFolders.Count
MsgBox "Do something with " & colFolders(lngC)
Next
End If
Set colFolders = Nothing
End Sub
Sub CollectSubFolders(oFolder As Folder)
Dim SubFolder As Folder
For Each SubFolder In oFolder.SubFolders
colFolders.Add SubFolder.Path, SubFolder.Path
Set oFolder = fso.GetFolder(SubFolder.Path)
CollectSubFolders SubFolder
Next
End Sub
Is anyone able to help me get this running please? I am trying to learn how
to manipulate foldes/subfolders and so far it's not going well! Thank you.
Set oFld = fso.GetFolder("E:\")
'Runtime Error 13 Type Mismatch
Option Explicit
'Add reference to Microsoft Scripting Runtime
Dim fso As New FileSystemObject
Dim colFolders As New Collection
Sub Demo()
Dim oFld As Folder
Dim lngC As Long
Set oFld = fso.GetFolder("E:\TEST")
'Runtime Error 13 Type Mismatch
MsgBox "Do something with: " & oFld
CollectSubFolders oFld
If colFolders.Count > 0 Then
For lngC = 1 To colFolders.Count
MsgBox "Do something with " & colFolders(lngC)
Next
End If
Set colFolders = Nothing
End Sub
Sub CollectSubFolders(oFolder As Folder)
Dim SubFolder As Folder
For Each SubFolder In oFolder.SubFolders
colFolders.Add SubFolder.Path, SubFolder.Path
Set oFolder = fso.GetFolder(SubFolder.Path)
CollectSubFolders SubFolder
Next
End Sub