OneInSolidarity
New Member
- Joined
- Aug 5, 2013
- Messages
- 2
This is the relevant code.
I want it to look for the latest .txt file in the folder and import it into a new worksheet. Currently when run no data appears. Can anyone see why this isn't working? I've selected the line I think most likely has the issue (bold).
Thanks in advance.
Code:
' Select file to import
Dim FileSys As FileSystemObject
Dim objFile As File
Dim myFolder
Dim strFilename As String
Dim dteFile As Date
Const myDir As String = "C:\Users\mlewis\Desktop\Supply Pro Feed\Admin activity"
'set up filesys objects
Set FileSys = New FileSystemObject
Set myFolder = FileSys.GetFolder(myDir)
'loop through each file and get date last modified. If largest date then store Filename
dteFile = DateSerial(1900, 1, 1)
For Each objFile In myFolder.Files
If objFile.DateLastModified > dteFile Then
dteFile = objFile.DateLastModified
strFilename = objFile.Name
End If
Next objFile
' Feed Macro
'
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
[B]"TEXT;" & objFile, Destination:=Range[/B]("A1"))
I want it to look for the latest .txt file in the folder and import it into a new worksheet. Currently when run no data appears. Can anyone see why this isn't working? I've selected the line I think most likely has the issue (bold).
Thanks in advance.
Last edited: