Sub Macro9()
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Macro4, _
Destination:=Range("$A$1"))
.Name = "Télécharger(2)"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Function Macro4() As String
Dim monrep As String, monfic As String, derdate As Date, ledernier As String
monrep = "C:\Documents and Settings\compta\Mes documents\Téléchargements\"
monfic = Dir(monrep & "*.csv")
derdate = DateSerial(1, 1, 1)
Do While monfic <> ""
If FileDateTime(monrep & monfic) > derdate Then
ledernier = monrep & monfic
derdate = FileDateTime(monrep & monfic)
End If
monfic = Dir
Loop
'MsgBox "le plus récent des fichiers csv dans ce répertoire est " & ledernier
Macro4 = ledernier
End Function