mdelatorre icon

Import text file into Excel with VBA

mdelatorre | PRO | 05/24/12 04:59:26 AM UTC | 0 ⭐ | 650 👁️ | Never ⏰ | []
VisualBasic |

620 B

|

None

|

0 👍

/

0 👎

Sub ImportData()
 
     Filename = InputBox("Enter the file path")
    'Filename = the full path to Your txt file eg."C:\MyDocuments\Mytxt.txt" 
    Open Filename For Input As #1
    Do While (Not EOF(1))
        ' In this case the file is delimited by , and contains several lines
    ' Read the file one line at the time
    Input #1, Streng
 
    'Input streng into and array
    StrArray = Split(Streng, ",")
    Call WriteToExcel(StrArray)
    Loop
    Close #1
End Sub
 
Sub WriteToExcel(StrArray)
     For J = LBound(StrArray) To UBound(StrArray)
       'Do what you want to do with the data
    Next J
End Sub

Comments