Write Text File
VBA has its own facility so no need to use FSO here. From help
Dim MyIndex, FileNumber
For MyIndex = 1 To 5 ' Loop 5 times.
FileNumber = FreeFile ' Get unused file
' number.
Open "TEST" & MyIndex For Output As #FileNumber ' Create file name.
Write #FileNumber, "This is a sample." ' Output text.
Close #FileNumber ' Close file.
Next MyIndex
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Florian Strahberger" wrote in message
...
You could use the 'Scripting.FileSystemObject' from WSH. Here is a sample
code:
'------------------------------------------------------------
' To use this example, go to Extras -- AddIns
' and inclde 'Microsoft Scripting Runtime'.
'------------------------------------------------------------
Const PathToFile = "C:\_work\examples\test.txt"
Sub TestIt()
Dim oFs As New Scripting.FileSystemObject
Dim oFile As Scripting.TextStream
'------------------------------------------------
' open existing file for appending,
' if the file does not exist a new one is created
'-------------------------------------------------
Set oFile = oFs.OpenTextFile(PathToFile, ForAppending, True)
oFile.WriteLine ("Hello World from Excel")
oFile.Close
' cleanup
Set oFile = Nothing
Set oFs = Nothing
End Sub
"Nigel" schrieb:
Hi All
I have an Excel application that loads a workbook from a data source on
a
daily basis, acts on it and produces a summary report. What I now wish
to
add is a logging function, whereby the data rows (up to 1000 per day)
can be
saved to an archive file. How can I do the following from within
VBA.....
1. Create / Open a Text file
2. Write and subsequently append Excel data to this file
3. Close the file
Thanks
--
Cheers
Nigel
|