MrExcel Publishing
Your One Stop for Excel Tips & Solutions

output cell range to text file

Posted by Wayne Goldstone on December 18, 1999 7:38 PM

Can anybody tell me the best way to output a range of cells to a text file at regular intervals. ie logging data.

Posted by Ivan Moala on December 19, 1999 1:14 AM

Hi Wayne
Try something like this;

Sub Write1CellText()

Open "C:\Windows\Desktop\Test.txt" For Output As #1
Print #1, Range("A1").Text
Close #1

End Sub

Sub WriteRangeCellsText()
Dim MyRg As Range
Dim ocell As Range
Dim TxtToWrite As String

Set MyRg = Range("a1:D1")
For Each ocell In MyRg
TxtToWrite = TxtToWrite & ocell.Text
Open "C:\Windows\Desktop\Test.txt" For Output As #1
Print #1, TxtToWrite
Close #1

End Sub

Use this in combo with application.ontime
Have a look @ online help.