Thanks JBeau for the encouragement.
This is the recording of the steps I use to get the data I want:
Sub getdatalatestfile()
'
' getdatalatestfile Macro
'
' Keyboard Shortcut: Ctrl+Shift+W
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\Admin\Downloads\Station vélo_ On street__ Yes Publicly Available__ Yes (27).csv" _
, Destination:=Range("$A$1"))
.Name = "Station vélo_ On street__ Yes Publicly Available__ Yes (27)"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
I'm a little unsure how to join this code to that supplied by Pike. I'm not particularly good at reading code but I guess the key is in the first couple of lines.
I think I'd start the code with the first part of Pikes macro:
Option Explicit
Sub newestfileinfolderastext()
Dim xDir As String, csvFile As String, LastestFile As String
Dim ModDate As Date, LastDate As Date
Dim FileObj As Object, wsXLS As Object, wbCSV As Object
Set wsXLS = ActiveWorkbook.Sheets("Sheet1") '
Set FileObj = CreateObject("Scripting.FileSystemObject")
xDir = "C:\Users\Admin\Downloads"
csvFile = Dir(xDir & "\*.csv")
Do While csvFile <> ""
ModDate = FileObj.GetFile(xDir & "\" & csvFile).DateLastModified
If LastDate < ModDate Then
LastestFile = csvFile
LastDate = ModDate
End If
csvFile = Dir()
Loop
But where would I insert:
?
Yep, I'm still beginning at this.
HW
Bookmarks