Importing data in a text file

The following example reads a text file and then places each line of data in a single cell (beginning with the active cell):

Sub ImportData()

Open "c:\windows\desktop\textfile.txt" For Input As #1

Do Until EOF(1)

Line Input #1, data ActiveCell.Offset(r, 0) = data r = r + 1


Close #1 End Sub

In most cases, this procedure won't be very useful because each line of data is simply dumped into a single cell. You can, however, choose the Data ^ Text to Columns command to parse the data to columns.

0 0

Post a comment