Sub GetTextFiles()
Dim lngCounter As Long, wbText As Workbook
On Error GoTo ErrHandler
Application.DisplayAlerts = False
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.FileType = msoFileTypeAllFiles
.LookIn = "C:temptext files" 'Change this to your folder name
.Execute
For lngCounter = 1 To .FoundFiles.Count
If Right(.FoundFiles(lngCounter), 4) = ".txt" Then
Workbooks.OpenText .FoundFiles(lngCounter)
ActiveSheet.UsedRange.Copy
ActiveWorkbook.Close False
ThisWorkbook.Sheets.Add
ActiveSheet.Paste
End If
Next lngCounter
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
Application.ScreenUpdating = True
MsgBox Err.Description, vbExclamation, "Ooops, an error occurred"
End Sub
Sub GetTextFiles()
Dim lngCounter As Long, wbText As Workbook
On Error GoTo ErrHandler
Application.DisplayAlerts = False
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.FileType = msoFileTypeAllFiles
.LookIn = "C:temptext files" 'Change this to your folder name
.Execute
For lngCounter = 1 To .FoundFiles.Count
If Right(.FoundFiles(lngCounter), 4) = ".txt" Then
Workbooks.OpenText Filename:=.FoundFiles(lngCounter), tab:=True, DataType:=xlDelimited
ActiveSheet.UsedRange.Copy
ActiveWorkbook.Close False
Range("A" & ActiveSheet.UsedRange.Rows.Count + 1).PasteSpecial
End If
Next lngCounter
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
Application.ScreenUpdating = True
MsgBox Err.Description, vbExclamation, "Ooops, an error occurred"
End Sub