Howdy Raihnman,
It kind of depends what you're doing, but here's an example:
Sub PrintToTextFile()
Dim FileNum As Integer, cl As Range, z As Integer, y As Integer
Dim myStr As String
FileNum = FreeFile ' next free filenumber
'Open "C:\Temp\TEXTFILE.TXT" For Output As #FileNum ' creates the new file
Open "C:\temp\TEXTFILE.TXT" For Append As #FileNum
Print #FileNum, [a1]
z = 10
For Each cl In [b10:f30]
y = cl.Row
If y = z Then
myStr = myStr & "|" & cl
'appends the input to an existing file write to the textfile
Else: Print #FileNum, myStr
z = cl.Row
myStr = "": myStr = myStr & "|" & cl
End If
Next
'appends the input to an existing file write to the textfile
Print #FileNum, myStr
Close #FileNum ' close the file
End Sub
Hope this helps. Incidentally, copy this code into Word before pasting it into your VBE module.


LinkBack URL
About LinkBacks



Reply With Quote


Bookmarks