Cursetin
Cursetin

Reputation: 25

VBA Excel Import delimited txt file when having a partial file name

This seems like a simple task, but I can't put my finger on it, it just won't work. I need to import a delimited txt file by vba, that has a random value at the end, this is what I tried:

c02 = Dir("T:\bla\DERP-_-" & Format$(Date, "YYYY-MM-DD") & "_*.txt")

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;" & c02 _
        , Destination:=Range("$A$1"))
        .Name = _
        "Extract"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With

So the full path for today would be: T:\bla\DERP-_-2014-06-19_08-19.txt

Tomorrow could be: T:\bla\DERP-_-2014-06-20_09-12.txt

Why won't this work? I'm so frustarted that something this simple is not working

Huuuuge thanks in advance

Upvotes: 0

Views: 488

Answers (1)

bmgh1985
bmgh1985

Reputation: 789

You need to add the full path to where your querytable is being generated. Dir only returns the filename, not the full path

Upvotes: 2

Related Questions