Importing a text file to a range : Excel to Text File « Excel « VBA / Excel / Access / Word





Importing a text file to a range

 
Sub ImportRange2()
    Set ImpRng = ActiveCell
    Open ThisWorkbook.Path & "\textfile.txt" For Input As #1
    txt = ""
    Application.ScreenUpdating = False
    Do While Not EOF(1)
        Line Input #1, vData
        For i = 1 To Len(vData)
            char = Mid(vData, i, 1)
            If char = "," Or i = Len(vData) Then
                Debug.Print txt
            Else
                If char <> Chr(34) Then _
                  txt = txt & Mid(vData, i, 1)
            End If
        Next i
    Loop
    Close #1
    Application.ScreenUpdating = True
End Sub

 










Related examples in the same category

1.TextToColumns Example
2.Exporting a range to a text file