0
这似乎是一个简单的任务,但我不能把它放在手指上,它只是不起作用。 我需要导入由VBA分隔txt文件,有在最后一个随机值,这是我的尝试:VBA Excel导入带有部分文件名的分隔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
所以对于今天的完整路径将是:T:\bla\DERP-_-2014-06-19_08-19.txt
明天可能是:T:\bla\DERP-_-2014-06-20_09-12.txt
为什么不能正常工作?我很frustarted的东西这个简单的事先不
DOP你的意思是将其更改为 'C01 = “T:\喇嘛\” C02 = DIR( “DERP -_-” 与格式$(日期,“YYYY -MM-DD“)&”_ *。txt“) With ActiveSheet.QueryTables.Add(Connection:= _ ”TEXT;“&c01&c02 _' ? Stil ldoesn't work,or understand that understand你错了吗? – Cursetin
It works !!!'c01 =“T:\ bla \”c02 = Dir(c01&“DERP -_-”&Format $(Date,“YYYY-MM-DD”)&“_ *。 txt“)With ActiveSheet.QueryTables.Add(Connection:= _”TEXT;“&c01&c02 _' – Cursetin
That's the one。Yes,you still need the full path for'Dir' to work,but the result from'Dir '只是一个文件名,所以你需要重新附加文件夹路径以获得完整的文件ference。 – bmgh1985