Shawnathon
New Member
- Joined
- Feb 16, 2011
- Messages
- 45
Hi There Forum,
I have a code here that I use to generate a text file.
What I need to do is run the whole list in one shot. I have some lists with 10,000 names.
Right now i need to change the range amount and the name of the file to run the next text file. I run it for every 30 rows. I know I need to pre make the text file for it to save. (Do you know if XL can be coded to pre make the Text files also? or what program can do that? thanks)
So say I have 5000 rows to complete, it will generate 167 text files with 30 rows each in them. Please let me know if you have any questions, thanks!
Shawn
I have a code here that I use to generate a text file.
What I need to do is run the whole list in one shot. I have some lists with 10,000 names.
Right now i need to change the range amount and the name of the file to run the next text file. I run it for every 30 rows. I know I need to pre make the text file for it to save. (Do you know if XL can be coded to pre make the Text files also? or what program can do that? thanks)
Code:
Sub MakeTextFile()
'*** change dimension to use late binding ***
Dim FSO As Object 'FSO As Scripting.FileSystemObject
Dim TextStr As Object 'TextStr As Scripting.TextStream
Dim Rng As Range
'*** use create object to create a FileSystemObject ***
'Set FSO = New Scripting.FileSystemObject
Set FSO = CreateObject("Scripting.FileSystemObject")
'*** Open a text file for appending ***
'*** if it does not already exist, then create it ***
ForAppending = 8
Set TextStr = FSO.OpenTextFile(Filename:="C:\MyFile\MyFile.txt", _
IOMode:=ForAppending, create:=True)
For Each Rng In Range("A1:A30")
If Rng.Value <> "" Then
TextStr.WriteLine Text:=Rng.Value
End If
Next Rng
TextStr.Close
Set FSO = Nothing
End Sub
So say I have 5000 rows to complete, it will generate 167 text files with 30 rows each in them. Please let me know if you have any questions, thanks!
Shawn
Last edited by a moderator: