vendredi 27 février 2015

Import latest CSV into Excel based on dynamic date property of file

Stackbros


I have some VBA which I'm using to import a .csv file from a specified folder into Excel. Once imported the script performs some other transformations such as delimiting and offsetting. See below.



Sub OpenTextFile ()

Dim FilePath As String

FilePath = "C:\Foldername\Foldername\Foldername\File_name.CSV"

Open FIlePath For Input As #1

row_number = 0

Do Until EOF(1)

Line Input #1, LineFromFile

LineItems = Split(LineFromFile, ",")

ActiveCell.Offset (row_number, 0).Value = LineItems (2)
ActiveCell.Offset (row_number, 1).value = LineItems (1)
ActiveCell.Offset (row_number, 2).Value = LineItems (0)

row_number = row_number + 1

Loop

Close #1

End Sub


What I really want to do is modify this so that when I run this I'm alsways importing the latest file from the folder, based on the date property of the file in the folder.


Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire