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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,836
Office Version
  1. 2010
Platform
  1. Windows
If you want it in numerical order, add a leading zero to the single-digit numbers.
 
Upvote 0

Jan Erik

Board Regular
Joined
May 24, 2005
Messages
78
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,195,594
Messages
6,010,625
Members
441,558
Latest member
lambierules

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
Top