This code will read a line from a text file:
set file = CreateObject("Scripting.FileSystemObject").OpenTextFile("c:\number.txt", 1)
text = file.ReadLine
MsgBox text
How can I make it read repeatedly one line after another from the same file? I guess, I should use a loop here, right? I need it to read the first line from the file at the first iteration, the second line at the second iteration, the third one at the third and so on till all the lines have been read. How can I do it?
Important addition: I need the code to operate on each line one by one - not all at once!
Use the
ReadAll()
method:(Might be of interest: FileSystemObject Sample Code)
With a loop:
If for some reason you want to use the in-built VBA file handling routines, you would use code like this:
I wrote a VBA routine that reads a text file and insert a new slide for each sentence in the text.
First, in slide #1, add a button that calls the macro named "generate"
Source code goes:
Download file: http://konahn.tistory.com/attachment/cfile8.uf@2175154C573D3BC02A2DFA.pptm
You can add a reference* to the Windows Script Host Object Model, it will help you with the FileSystemObject Object, because you can then say:
Which will allow you to use intellisense to see the various properties and the Object Browser to explore the library.
* In the code window, choose Tools, References and tick the box beside the library you want.