Merging text files into one file...

shelim481

New Member
Joined
Aug 30, 2018
Messages
28
Can someone help im trying to merge text files into one file...
using VBA, basically all is want is a all the text files in the location of the excel file to be merged, into one file and then all other txt files to be deleted once merged..

I have tried this but it did not work...

Code:
strPath = Application.ActiveWorkbook.Path & ""
[/COLOR][COLOR=#333333]Shell "cmd.exe copy /c """ & strPath & "*.txt"" """ & strPath & "Consolidated.txt""", 0[/COLOR]
 
Last edited by a moderator:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Code:
 Dim MyPath As String
    MyPath = Application.ActiveWorkbook.Path & "\"

Code:
    If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"    DOScommand = "COPY " & MyPath & "*.txt " & MyPath & "ALL.txt"
    Shell Environ("comspec") & " /c " & DOScommand, vbHide



aaah got this working but only for desktop...it doesn't work anywhere else...can some one help...
 
Upvote 0
If you post a your workbooks to a third party site, I will give you my solution. The beauty of PQ is that once the data has been entered and the query built, any additional data added to the files will automatically update your output. No additional work is required beyond clicking on the refresh button. PQ was developed by MS to do exactly what you are asking for with excel files.
 
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