Importing Multiple TXT Files

mrtim2232

New Member
Joined
Aug 24, 2017
Messages
48
Morning All,

I found the following code online hoping that it would allow me to download multiple txt files onto the same sheet from a memory stick however when I try and run the program it faults out on the underlined line with "Object Doesn't Support This action" any ideas or suggestions would be appreciated


Sub GetTextFiles()
Dim lngCounter As Long, wbText As Workbook




Application.DisplayAlerts = False
Application.ScreenUpdating = False


With Application.FileSearch
.NewSearch
.FileType = msoFileTypeAllFiles
.LookIn = "E:/SBUB"
.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




End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Unfortunately FileSearch was removed in 2007.
This is untested
Code:
Sub GetTextFiles()

    Dim FldrPth As String
    Dim FlNme As String
    
Application.DisplayAlerts = False
Application.ScreenUpdating = False
    
    FldrPth = "E:/SBUB"
    FlNme = Dir(FldrPth & "*.txt")
    Do While FlNme <> ""
        Workbooks.OpenText (FldrPth & FlNme)
        ActiveSheet.UsedRange.Copy
        ActiveWorkbook.Close False
        ThisWorkbook.Sheets.Add
        ActiveSheet.Paste
        FlNme = Dir
    Loop

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top