John_w Professional

  • Member since Nov 20th 2012
  • Last Activity:
Posts
918
Likes Received
7
Points
4,677
Trophies
1
Profile Hits
439
  • Hello Mr.John,


    Good day,


    I'm new here and posted full thread


    Link


    VERTICAL Sorting Order for SUB-FOLDERS


    I’m trying to sort out your VBA code that is working in VERTICAL Sorting Order of SUB-FOLDERS

    Please help me to work this VBA code to work in HORIZONTAL Sorting Order of SUB-FOLDERS. I attached two photos please someone help me I really appreciate your great efforts and time.


    Thank You Sir John,


    http://imgur.com/gallery/sNDFytJ


    VBA code


    Public Sub Hierarchical_Folders_and_Files_Listing2()



    Dim startFolderPath As String

    Dim startCell As Range

    Dim n As Long


    startFolderPath = "Z:\Central Region (Riyadh)"


    With Sheets("Sheet1")

    .Cells.Clear

    .Activate

    Set startCell = .Range("A1")

    End With


    n = List_Folders_and_Files2(startFolderPath, startCell)



    End Sub



    Private Function List_Folders_and_Files2(folderPath As String, destCell As Range) As Long



    Static FSO As Object

    Dim thisFolder As Object, subfolder As Object

    Dim fileItem As Object

    Dim n As Long


    If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject")


    Set thisFolder = FSO.GetFolder(folderPath)


    'Add hyperlink for this folder


    destCell.Parent.Hyperlinks.Add Anchor:=destCell, Address:=thisFolder.Path, TextToDisplay:=thisFolder.Name



    'List subfolders in this folder


    n = 0

    For Each subfolder In thisFolder.Subfolders

    n = n + 1 + List_Folders_and_Files2(subfolder.Path, destCell.Offset(n + 1, 1))

    Next



    List_Folders_and_Files2 = n



    End Function