kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
I have this code, which I copied from this same platform at:
written by @AlphaFrog .
Which means that I am able to determine if there is/are subfolder(s) in my mainfolder or not.
If there is/are subfolder(s), then I would like to switch the path from:
to
Which is to say that if there are say 3 subfolders, then I will switch the path 3 times for SUB1, SUB2, SUB3
I understand the loop will be something like this:
But I dont know how to code it.
I will be very glad to get solution for this problem.
Thanks in advance.
VBA to check if folder has subfolder in it
I found this code to check if a folder has files in it but I need to check if the folder has a sub folder in it, how can I do this in Excel 2003 Thanks Dim fs, strFolderPath, oFolder Set fs = CreateObject("Scripting.FileSystemObject") strFolderPath = "d:\" ' this is your folder Set oFolder...
www.mrexcel.com
written by @AlphaFrog .
Which means that I am able to determine if there is/are subfolder(s) in my mainfolder or not.
If there is/are subfolder(s), then I would like to switch the path from:
Code:
strFolderPath = ThisWorkbook.Path & "/MAINFOLDER/"
to
Code:
strFolderPath = ThisWorkbook.Path & "/MAINFOLDER/SUB1"
I understand the loop will be something like this:
Code:
For Each SubFolder In Folder.SubFolders
'''''msgbox to display path
Next
Code:
Sub sub_folders_check()
Dim fs, strFolderPath, oFolder
Set fs = CreateObject("Scripting.FileSystemObject")
strFolderPath = ThisWorkbook.Path & "/MAINFOLDER/"
Set oFolder = fs.GetFolder(strFolderPath)
If (oFolder.SubFolders.Count = 0) Then
'folder is Empty
Else
'folder isn't empty
strFolderPath = ThisWorkbook.Path & "/MAINFOLDER/SUB1"
End If
Set fs = Nothing
End Sub
I will be very glad to get solution for this problem.
Thanks in advance.