mporting multiple text files into Excel with corresponding fil
That was not mentioned in the original post..I have modified to suit your
requirement.
Sub Macro()
Dim strFolder As String, strFile As String, lngRow As Long
Dim strData As String, arrData As Variant, intFile As Integer
strFolder = "D:\PhoneNo"
If Right(strFolder, 1) < "\" Then strFolder = strFolder & "\"
strFile = Dir(strFolder & "*.txt", vbNormal)
Do While strFile < ""
intFile = FreeFile
Open strFolder & "\" & strFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strData
arrData = Split(strData, ",")
lngRow = lngRow + 1
Range("A" & lngRow) = strFile
Range("B" & lngRow).Resize(, UBound(arrData) + 1) = arrData
Loop
Close #intFile
strFile = Dir
Loop
End Sub
--
Jacob
"avi" wrote:
Thanks Jacob! Works perfect!
Just one note (that I forgot to mention): data in my text files is
comma delimited.
Your code imports correctly filenames & data BUT all the data is
imported into one cell.
OK, I can use "text to columns" but would like to have it
delimited.... :-)
.
|