Friday, 25 October 2013

Excel Macro to read data from text file

Sub readFile()
'Excel macro to read a text file

Dim myfso As Scripting.FileSystemObject
Dim stream As Scripting.TextStream

Set myfso = New Scripting.FileSystemObject

'open text file in read mode.
Set stream = myfso.OpenTextFile("c:\tempfile.txt", ForReading, True)

MsgBox stream.ReadAll

End Sub


What do you think on above excel macro topic? Please provide your input, comments, questions on excel macro. I will try to reply as soon as possible. I value your opinion on Excel Macros.

1 comment:

  1. why not:

    Dim fline As String
    Dim inName As String
    Dim inFile As Integer
    ...
    inFile = FreeFile
    Open inName For Input As #inFile

    Do While Not EOF(inFile)
    Line Input #inFile, fline
    fline = RTrim(fline)
    ...
    Loop
    Close #inFile

    ReplyDelete

Popular Posts

Search This Blog