List folderstructure UNSORTED

Jan Erik

Board Regular
Joined
May 24, 2005
Messages
78
Hello,

I've got a VBA procedure which lists all folders and subfolders in a sheet:

======================================================
Sub List_Folderstructure()
'
' Include reference to MS Scripting Runtime library Scrrun.dll
'
Dim objFSO As Scripting.FileSystemObject
Dim rngOut As Range
Dim strRoot As String

Set objFSO = New Scripting.FileSystemObject
Set rngOut = Cells(1, 1) 'start of output
strRoot = ActiveWorkbook.Path

rngOut = strRoot

rngOut.EntireRow.Range("A1") = strRoot

Set rngOut = rngOut.Offset(1, 1)

FolderStructure objFSO.GetFolder(strRoot), rngOut

End Sub

Sub FolderStructure(Fld As Scripting.Folder, Output As Range)

Dim objFolder As Scripting.Folder

For Each objFolder In Fld.SubFolders
Output = objFolder.Name
Output.EntireRow.Range("AA1") = objFolder.Path

Set Output = Output.Offset(1, 1)
FolderStructure objFolder, Output
Set Output = Output.Offset(0, -1)
Next

End Sub

====================================================
It works great except that the list comes out in alphabetic order, like this:

FOLDERS:
1. MANAGEMENT
10. COST CONTROL
11. CONTRACTS & PROCUREMENT
12. OPERATIONAL REPORTS
13. PROJECT DELIVERABLES
14. WELL REVIEW & POST ANALYSIS
15. PROJECT MANAGEMENT SYSTEM
2. SUB-SURFACE
3. WELL PLANNING
4. WELL TEST PLANNING
5. HSEQ
6. RIG
7. OPERATIONS
8. LOGISTICS
9. CORRESPONDENCE

I need the list in the correct and actual order. If anybody has a solution here I will be very greateful:) !!!

Regards
Jan Erik
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
If you want it in numerical order, add a leading zero to the single-digit numbers.
 
Upvote 0
If you want it in numerical order, add a leading zero to the single-digit numbers.

Thanks, but the folder trees already exist and have no leading zeros. I want the list to be in the same way as it appear in Windows explorer, not sorted at all.
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,301
Members
448,885
Latest member
LokiSonic

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