Check for newest *.txt file and import data

G

Guest

I want to be able to search a specifik folder for all .txt files, check the date to find the newest and import the data
How to import, I know, I just need to be able to "catch" the filename on newest file
How do I do that?
 
R

Rob van Gelder

Here's a way to get the latest file:

Sub test()
Const cPath = "C:\WINDOWS\"
Dim strFile As String, dtmFile As Date
Dim strLatestFile As String, dtmLatestFile As Date

strFile = Dir(cPath)

Do Until strFile = ""
dtmFile = FileDateTime(cPath & strFile)
If dtmFile > dtmLatestFile Then
strLatestFile = strFile
dtmLatestFile = dtmFile
End If
strFile = Dir
Loop

MsgBox strLatestFile
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


ALK said:
I want to be able to search a specifik folder for all .txt files, check
the date to find the newest and import the data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top