VBA Excel具有部分文件名时导入分隔的txt文件

这似乎是一个简单的任务,但我不能把它的手指,它不会工作。 我需要通过vba导入一个分隔的txt文件,在最后有一个随机值,这是我试过的:

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 

所以今天的完整path是: T:\bla\DERP-_-2014-06-19_08-19.txt

明天可能是: T:\bla\DERP-_-2014-06-20_09-12.txt

为什么这不工作? 我很沮丧,这个简单的东西不起作用

霍夫格提前感谢

您需要将完整path添加到生成查询表的位置。 Dir只返回文件名,而不是完整的path