Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping within an Opentxt Command

Status
Not open for further replies.

kat6787

Technical User
Jan 11, 2007
7
US
I'm fairly new to VBA. I can do some pretty basic commands, but this one is way over my head. Is it possible to loop a filename within an opentxt command? A co-worker is trying to write a code that will open several output.txt files to be used in the next part of his analysis. All the files have the same naming convention shown;
C:\...\path 1.txt
with the number incrementing by 1 each time he makes a run.

Is it possible to use OpenTextFile("C:\path 1.txt") command but use a for loop to increment the path number.

Basically he wants to do something like this
for i = 1 to 10
OpenTextFile("C:\path i.txt")

But I'm not sure if it will work since the increment happens within the text string. Any comments or advice is much appreciated.

Thanks in advance.

Cheers,
Kat

 
I think you need to use string concatenation, but you need to capture the returned TextStream:
Code:
dim ts(10) as textstream
for i=1 to 10
  fnam="c:\blah\blah\path " & i & ".txt"
  ts(i)= openTextFile(fnam)
next


_________________
Bob Rashkin
 
Thanks for the help. It worked great.

Kat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top