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
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