etpeterson
New Member
- Joined
- Jan 19, 2005
- Messages
- 18
I have some code that using filesearch to search a directory for all .txt files. This code stores in n, the number of files and FS.FoundFiles is an object where the file names are. At least that's what I think it does and have been told that as well. Here's the code just to be sure:
Set FS = Application.FileSearch
With FS
.NewSearch
.LookIn = Range("B5")
.Filename = "*.txt"
n = .Execute
End With
I then want to run some code on each file. This is what I have, and I believe all I have is a syntax error:
Dim counter
For counter = 1 To n
Workbooks.OpenText Filename:=FS.FoundFiles.counter _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, , 1), _
Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
Sheets(FS.FoundFiles.counter).Select
Sheets(FS.FoundFiles.counter).Move After:=Workbooks("Fault Log Creator.xls").Sheets(counter)
Call Auto_Format
Sheets("Sheet1").Select
Next counter
Application.StatusBar = False
In the bolded section, I want to open each file in sequence. My main question is how do I access the list of files in FS.FoundFiles. I'm currently trying:
Workbooks.OpenText Filename:=FS.FoundFiles.counter
Where I was hoping that FS.FoundFiles.counter would be the filename of the Xth file. I guess I'm wrong.
Please Help!!
Thanks,
Eric
Set FS = Application.FileSearch
With FS
.NewSearch
.LookIn = Range("B5")
.Filename = "*.txt"
n = .Execute
End With
I then want to run some code on each file. This is what I have, and I believe all I have is a syntax error:
Dim counter
For counter = 1 To n
Workbooks.OpenText Filename:=FS.FoundFiles.counter _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, , 1), _
Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
Sheets(FS.FoundFiles.counter).Select
Sheets(FS.FoundFiles.counter).Move After:=Workbooks("Fault Log Creator.xls").Sheets(counter)
Call Auto_Format
Sheets("Sheet1").Select
Next counter
Application.StatusBar = False
In the bolded section, I want to open each file in sequence. My main question is how do I access the list of files in FS.FoundFiles. I'm currently trying:
Workbooks.OpenText Filename:=FS.FoundFiles.counter
Where I was hoping that FS.FoundFiles.counter would be the filename of the Xth file. I guess I'm wrong.
Please Help!!
Thanks,
Eric