Macro to Sort CSV files in folder in Custom Order

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have a macro to sort CSV files in a folder alphabetically

I need to amend this so that the files are sorted in a custom sort order for eg

BTMSales.csv
AtlSale.csv
CPMsales.csv
MWESales.csv
EBR1Sales.csv
BYPSales.csv Etc



Code:
 Sub Sort_FolderAphabetical()

    Dim sPath
    Dim sExtension
    Dim oShellApp
    Dim oFolder
    Dim oFolderItems
    Dim oFolderItem

    sPath = "c:\Sales Files\"
    sExtension = "*.csv"

    Set oShellApp = CreateObject("Shell.Application")
    Set oFolder = oShellApp.Namespace(sPath)
    Set oFolderItems = oFolder.Items()
    oFolderItems.Filter 64 + 128, sExtension ' 32 - folders, 64 - not folders, 128 - hidden
    For Each oFolderItem In oFolderItems
        Debug.Print oFolderItem.Path
    Next

End Sub


It would be appreciated if someone could amend my code
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,214,892
Messages
6,122,112
Members
449,066
Latest member
Andyg666

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