Re-order Files in a Folder using an Array

jagrenet

Board Regular
Joined
Feb 23, 2022
Messages
81
Office Version
  1. 365
  2. 2013
  3. 2011
  4. 2010
Platform
  1. Windows
Good Day Gurus !!

I have an idea I am trying to get to work but, not sure exactly how to approach it, .... or if it can be done.
I have a folder with files,(13 files) all of the same type, and date, .... the only thing different are the names and length of names.

By default, they are listed Alphabetically.
What I am needing to do is "sort" them in a very specific order which is not Alphabetical. I have the filenames in a spreadsheet listed in the order I need and have that order assigned to an array.
Is there a way to use my array with DIR() ..... FSO ..... or some other method to re-arrange the files from within my VBA code, that would not require any user input?

Thanks in advance !!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
All I can think is that you give each file a prefix which places them in the right ascending order.
 
Upvote 0
All I can think is that you give each file a prefix which places them in the right ascending order.
I had considered that. But instead, using a "suffix" just prior to the extension. Something like "FilenameThis-1.docx .... FillenameThat-2.docx" and so on. With that in mind, ... the Array is already ordered the way I need it to be so, ..... is there a way to utilize the Array Indexes to make that happen, at runtime ?? - For that matter, ..... the filenames could be prefixed with the Array Index numbers and that would be just fine as well. These files are ultimately going to be deleted at the end anyway. Can I make my code do that ???
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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