Saladsamurai
11-20-2009, 06:46 AM
I have a loop, for each iteration it creates a new text file.
I want it to write the file to a particular folder; if that folder does not exist, I want Excel to create it.
For example:
Sub Test3()
Dim i As Integer
For i = 1 to 3
Open "Z:\Casey B\Main Folder\NewFile" & i & ".txt" For Output As #3
Print #3, i
Close #3
Next
End Sub
The results oft is should be as follows: If the folder "Main Folder" does not exist (which it does not on the FIRST iteration), then create it.
When the loop completes, there should be one folder called "Main Folder" and it should contain 3 text files...NewFile1, NewFile2, NewFile3.
As it stands, I get a "Path Not Found" error (duh...).
How can I remedy this?
Thanks so much,
Casey B
I want it to write the file to a particular folder; if that folder does not exist, I want Excel to create it.
For example:
Sub Test3()
Dim i As Integer
For i = 1 to 3
Open "Z:\Casey B\Main Folder\NewFile" & i & ".txt" For Output As #3
Print #3, i
Close #3
Next
End Sub
The results oft is should be as follows: If the folder "Main Folder" does not exist (which it does not on the FIRST iteration), then create it.
When the loop completes, there should be one folder called "Main Folder" and it should contain 3 text files...NewFile1, NewFile2, NewFile3.
As it stands, I get a "Path Not Found" error (duh...).
How can I remedy this?
Thanks so much,
Casey B