web analytics

VBA: how to read text file

This is just example, how to read text file in Visual Basic for Applications (for example, in Excel macro).

It’s just a stub: there is no error processing here, the source file is really text file, no problems with permissions etc.

Sub read_from_text_file()

txtFile = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If txtFile = False Then
    MsgBox "No file to process"
    Exit Sub
End If

Open txtFile For Input As #1
      Input #1, myString
      MsgBox myString
Close #1
End Sub

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>





A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.