Neversleepin 0 Junior Poster in Training

Hello,

i would to import the last modified txt file from a directory (c:\Folder) using a macro in Excel.
I have a folder which is incremented everyday by a new txt file.
The goal is to import the last txt file added in the direrctory.

I've already created a an Excel file with a button affected to macro.

Here is the code:


Sub Import()
'
' Import Macro
' Macro saved on 02/03/2011 by StYellowknife3000
'

'

With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Folder\File_01.txt", Destination:= _
        Range("A1"))
        .Name = "File_01"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 932
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.