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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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