Hi,
I have a series of .txt files than need to be importing in order and processed in EXCEL. I'm trying to sort it first and then processed one by one.
The problem is when I'm using .Foundfiles(i) in the QueryTable. connection to indicate the path, it pops up the window to let you select the file, where I thought it should directly load .FoundFiles(i). Here is part of the file. Any help would be greatly appreciated!
Set fs = Application.FileSearch
With fs
.LookIn = "C:\Documents and Settings\mx1000\Desktop\VBA"
.Filename = "*.txt"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
'fsort(i) = .FoundFiles(i)
'import data
Sheets("Row data").Select
Range("A1").Select
With Selection.QueryTable
.Connection = "TEXT;C:\Documents and Settings\mx1000\Desktop\VBA\.FoundFiles(i)"
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
...........................
I have a series of .txt files than need to be importing in order and processed in EXCEL. I'm trying to sort it first and then processed one by one.
The problem is when I'm using .Foundfiles(i) in the QueryTable. connection to indicate the path, it pops up the window to let you select the file, where I thought it should directly load .FoundFiles(i). Here is part of the file. Any help would be greatly appreciated!
Set fs = Application.FileSearch
With fs
.LookIn = "C:\Documents and Settings\mx1000\Desktop\VBA"
.Filename = "*.txt"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
'fsort(i) = .FoundFiles(i)
'import data
Sheets("Row data").Select
Range("A1").Select
With Selection.QueryTable
.Connection = "TEXT;C:\Documents and Settings\mx1000\Desktop\VBA\.FoundFiles(i)"
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
...........................