VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Read a text file line by line

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.

Rate Read a text file line by line

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

Download this snippet    Add to My Saved Code

Read a text file line by line Comments

No comments have been posted about Read a text file line by line. Why not be the first to post a comment about Read a text file line by line.

Post your comment

Subject:
Message:
0/1000 characters