Open textfiles depending on date of the files

Solari

New Member
Joined
Jun 1, 2018
Messages
16
Hi!

I have a macro (that works) in alla other aspects than the opening of the textfile that contains the data I'm to use.

The files that should be opened (by a loop?) is updated monthly and named in sequential order.
There are however some characteristics that each file have that allows me to tell them apart.

Example: ANMPF01xxx, ANMPF02xxx and so on; where xxx is the number that's updated every month.

The code below is how I did it before the filenames started changing. I hade the predefined names in cells A10-A20.

How do I get in a variable that looks at file dates and then chooses the latest for all the different types?



Code:
arr = Sheets("Blad1").Range("A10:A20")

For f = LBound(arr, 1) To UBound(arr, 1)
    If Len(arr(f, 1)) > 0 Then
        MsgBox arr(f, 1)


File = arr(f, 1)
Workbooks.OpenText FileName:=File, origin:=xlWindows, DataType:=xlDelimited, Semicolon:=True, Tab:=False, Space:=False, Other:=False
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,104
Messages
6,170,125
Members
452,303
Latest member
c4cstore

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