Ignore "Closed" Folders

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello All

I am hoping someone can help on this please

One of our members kindly gave me this code which works great

The only issue is I want to ignore any folders that have "Closed" as the name in any folder but I don't know how to change the code

[Public Sub ScanSubfolders()
Dim FileSystem As Object
Dim HostFolder As String
Range("A1").Select
HostFolder = "S:\Branch Data\Test\folder\open\Open"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
End Sub
'---------
Sub DoFolder(Folder)
'---------
Dim SubFolder
Dim oFile

For Each SubFolder In Folder.SubFolders
'Debug.Print SubFolder
DoFolder SubFolder
Next

For Each oFile In Folder.Files
' Operate on each file
' Debug.Print Folder, oFile.Name, getFileProperty(oFile, 5)

ActiveCell.Value = Folder
ActiveCell.Offset(0, 1).Value = oFile.Name
ActiveCell.Offset(0, 2).Value = oFile.DateLastModified

ActiveCell.Offset(1, 0).Select 'next row
Next
End Sub]
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Add the code in RED. That should do it
Code:
Public Sub ScanSubfolders()
Dim FileSystem As Object
Dim HostFolder As String
Range("A1").Select
HostFolder = "C:\Test" '"S:\Branch Data\Test\folder\open\Open"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
End Sub


'---------
Sub DoFolder(Folder)
'---------
Dim SubFolder
Dim oFile


For Each SubFolder In Folder.SubFolders
'Debug.Print SubFolder
[COLOR=#ff0000][B]If InStr(1, SubFolder.Name, "closed") = 0 Then[/B][/COLOR] DoFolder SubFolder
Next


For Each oFile In Folder.Files
' Operate on each file
' Debug.Print Folder, oFile.Name, getFileProperty(oFile, 5)


ActiveCell.Value = Folder
ActiveCell.Offset(0, 1).Value = oFile.Name
ActiveCell.Offset(0, 2).Value = oFile.DateLastModified


ActiveCell.Offset(1, 0).Select 'next row
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top