Import TXT files VBA please help

roberttkim

Board Regular
Joined
Mar 5, 2009
Messages
97
Hey everyone,

I have a code that works great for importing multiple txt files and copying into one sheet in excel but I have a problem was hoping one of you experts can help with. One of the txt files we have sometimes gets copied into one cell. I'm thinking it's a delimiting issue on the original file? Every other file gets copied fine though. Would really appreciate the help.


Rich (BB code):
Sub test()
    Dim myDir As String, fn As String, txt As String, x
    myDir = "\\04vfile002\TREASOPS\Fixed Income and Treasury Operations\FedMail\09-2017" '<- change to actual folder path
    fn = Dir(myDir & "\*.txt")
    Do While fn <> ""
        txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(myDir & "" & fn).ReadAll
        x = Application.Transpose(Split(txt, vbCrLf))
        Sheets(1).Range("a" & Rows.Count).End(xlUp)(2).Resize(UBound(x, 1)).Value = x
        fn = Dir()
    Loop
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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