by c23lemon (1 Submission)
Category: Microsoft Office Apps/VBA
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating:
(2 Votes)

Purpose is to open up a text file and read the contents line by line.
Inputs
None.
Assumes
To modify for your use do the following:
1. Replace "folderName" and "fileName" to suit for your requirement.
2. Please make sure that when you define "folderName", that the backslash is included (Ex. C:\Dump\"
3. The variable "inputdata" will hold the current value of the line of text being read.
Note:
This code will only open the text file and read its contents line by line.
Code Returns
None.
Side Effects
None.
Sub ReadLineByLine()
' Variable Declarations
Dim folderName As String
Dim fileName As String
folderName = "C:\Dump\"
fileName = "test.txt"
Open folderName & fileName For Input As #1
Do While Not EOF(1)
Line Input #1, inputdata
MsgBox inputdata
Loop
Close #1
End Sub