-
Open File for Output:: What if file does not exist?
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:
[VBA]
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
[/VBA]
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules