Mega Code Archive

 
Categories / VisualBasic Script / Excel
 

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