This script allows you to read the contents of a plain text file.
VBScript
- 6440
- 1450
- 0
© 2024VBAmacros.net
1Open your favorite text editor. In our case we are going to useNotepad++
2Copy the VBScript code from below.
3Paste the code in the newly created file.
4Save the file with a ".vbs" extension.
5Run the script file by double-clicking on it or via the CMD console.
6That's it!
"Lorem Ipsum" text snippet kindly provided byLipsum.
Advertisem*nt
Code
' This script reads from a text file.Sub readFromTextFile() ' Set variables Dim fso Dim reader Dim filePath Dim currentLine Dim lineCount ' Set file path filePath = "F:\VBAmacros\VBScript\LoremIpsum.txt" ' Create a reader Set fso = Wscript.CreateObject("Scripting.FileSystemObject") ' Open text file Set reader = fso.OpenTextFile(filePath, 1, True, 0) ' Set initial line count lineCount = 0 ' Loop over lines Do While reader.AtEndOfStream = False ' Read a single line currentLine = reader.ReadLine ' Increment the line count by one lineCount = lineCount + 1 Loop ' Output text line in a message box MsgBox lineCount ' Release the reader object Set fso = NothingEnd Sub' Run the procedureCall readFromTextFile()
Advertisem*nt
Comments
Advertisem*nt
Created
12-Mar-2021
Last updated
19-Mar-2021
Related Macros
VBScript - Create A Blank WorkbookVBScript
- 5528
- 0
- 0
- 0
VBScript - Create A Blank DocumentVBScript
- 4967
- 0
- 0
- 0
Advertisem*nt
Random Macros
Excel - Count Cells With ValuesExcel
- 2868
- 0
- 0
- 0
Excel - Select First Empty Cell In A RowExcel
- 14324
- 1
- 0
- 0
Excel - Delete Empty CellsExcel
- 2590
- 0
- 0
- 0
VBScript - Create A Blank WorkbookVBScript
- 5528
- 0
- 0
- 0
VBAmacros.net
Code was successfully copied!
VBAmacros.net
Link was successfully copied!
VBAmacros.net
Please sign in!
VBAmacros.net
You've already voted!