looping through txt files and pasting into a excel worksheet

T

timmulla

Can anyone help me create code to accomplish the following:

I have a folder that has a bunch of text files in it. I would like to
programatically open each file in a folder that contains the text '_MAST' in
it, copy the contents, and then paste it into an excel worksheet. I would
like it to keep looping through all of the text files in the folder until
all of the contents are pasted into one excel worksheet.

Any help would be greatly appreciated.
 
T

timmulla

Hey Ron,

The code works great for combining the text files. Is there any way to move
the files that don't contain the text '_MAST' out of the folder before I run
the Merge-CSV_Files macro. I'm only trying to combine the files that have
that text.

I'm thinking that moving the other files to another folder before running
the macro will solve the problem.

Any information would be greatly appreciated.

--
Regards,

timmulla


Ron de Bruin said:
Hi timmulla

Try the example on this page
http://www.rondebruin.nl/csv.htm
 
R

Ron de Bruin

Hi

Change this part

'Create the bat file
Open BatFileName For Output As #1
Print #1, "Copy " & Chr(34) & foldername & "*_MAST*.txt" _
& Chr(34) & " " & TXTFileName
Close #1


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


timmulla said:
Hey Ron,

The code works great for combining the text files. Is there any way to move
the files that don't contain the text '_MAST' out of the folder before I run
the Merge-CSV_Files macro. I'm only trying to combine the files that have
that text.

I'm thinking that moving the other files to another folder before running
the macro will solve the problem.

Any information would be greatly appreciated.
 
T

timmulla

Thanks, Ron. The code works great. I just realized that it's importing the
header rows from each of my txt files. Is there a way to only import the
header row from the first file? Or is it easier to loop through the excel
outoput file and delete the duplicate header rows?

Any information would be greatly appreciated.
 
R

Ron de Bruin

Change the start row

StartRow _
:=1

And copy the header row manual in the sheet one time when the code is ready
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top