View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
excel-ant excel-ant is offline
external usenet poster
 
Posts: 26
Default Import data from multiple txt files into one xls file

Certainly,

http://somethinglikeant.110mb.com//e...ile_Import.xls

Just tried this and it worked a treat. I had 20 text files setup in
test.

-------------------------------------------------------------
Sub Import_Multiple_Text_Files()
Dim FileS As FileSearch
Dim F As Variant
Dim x As Integer
'switch calculation off to speed up macro
Application.Calculation = xlManual
'Pick up file path information
qfolder = [B5]
Set FileS = Application.FileSearch
With FileS
.NewSearch
.Filename = "*"
.LookIn = qfolder
.SearchSubFolders = True
.Execute
End With
x = 1
Sheets("Data").Select
For Each F In Application.FileSearch.FoundFiles
Open F For Input Access Read As #1
Do Until EOF(1)
Line Input #1, qdata
If qdata < "" Then
Cells(x, 1) = qdata
x = x + 1
End If
Loop
Close #1
Next F
End Sub
--------------------------------------------------------------------------------

You will have to setup your folder by typing it out int the Macro tab.
Let me know if you need any further tweaks or assistance.

http://www.excel-ant.co.uk