Hi
Try the following macro.
Sub copy_text()
Dim a As Long, x As Long
Dim f As String, b As String
Cells(1, 1) = "=cell(""filename"")"
Cells(1, 2) = "=left(A1,find(""["",A1)-1)"
Range("A2:A1000").ClearContents
Cells(2, 1).Select
f = Dir(Cells(1, 2) & "*.txt")
Do While Len(f) > 0
ActiveCell.Formula = f
ActiveCell.Offset(2, 0).Select
f = Dir()
Loop
x = Cells(Rows.Count, 1).End(xlUp).Row
MsgBox "there are " & x - 1 & " files"
For a = 2 To x Step 2
b = Cells(a, 1)
Range("AA:AA").ClearContents
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Worksheets("sheet2").Cells(1, 2) & b _
, Destination:=.Range("AA1"))
.Name = "eiys"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.Refresh BackgroundQuery:=False
End With
Range("AA42:AZ42").Copy
Range("B" & a).PasteSpecial
Range("AA43:AZ43").Copy
Range("B" & a + 1).PasteSpecial
Next a
MsgBox "Listing is complete."
End Sub
Ravi
Bookmarks