PDA

View Full Version : Copy and combine files using VBA



jd.smithuk
08-02-2017, 12:57 PM
Hi I have a directory with a number of txt files in eg A1.txt A2.txt Ae.txt I want to copy them all to a different directory and combine them in a single file

Set fso = CreateObject("Scripting.FileSystemObject")

From_File = "C:\temp\*.*"
To_File = "C:\fred.txt"

fso.CopyFile From_File, To_File, True

However when I run the above I get a file path error if I change to_File C:\ it copies the individual files perfectly.

Does copyfile not allow you to copy as per dos?

Thanks

John

mdmackillop
08-02-2017, 03:00 PM
See here (http://www.vbaexpress.com/forum/showthread.php?42541-Merge-multiple-txt-files-into-one-txt-thru-Excel-VBA&p=269719&viewfull=1#post269719)