-
If you have a file already you just need to define it's path and open it[VBA]Sub TextStreamTest()
Const strFilePath As String = "C:\Documents and Settings\Killian\Desktop\MY_TEXT_FILE.TXT"
Dim fs, f, ts, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(strFilePath)
Set ts = f.OpenAsTextStream(1, -2)
s = ts.ReadLine
MsgBox s
ts.Close
End Sub[/VBA]This will read the first line of the text file. If you want to read other lines then just loop through until the line number and return the last one[VBA]Sub TextStreamTest2()
Const strFilePath As String = "C:\Documents and Settings\Killian\Desktop\MY_TEXT_FILE.TXT"
Dim fs, f, ts, s
Dim i As Long
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(strFilePath)
Set ts = f.OpenAsTextStream(1, -2)
For i = 1 To InputBox("Enter line number:", "Read from text file")
s = ts.ReadLine
Next
MsgBox s
ts.Close
End Sub[/VBA]
K :-)

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules