ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   looping through txt files and pasting into a excel worksheet (https://www.excelbanter.com/excel-programming/420375-looping-through-txt-files-pasting-into-excel-worksheet.html)

timmulla

looping through txt files and pasting into a excel worksheet
 
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.

--
Regards,

timmulla

Ron de Bruin

looping through txt files and pasting into a excel worksheet
 
Hi timmulla

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

--

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


"timmulla" wrote in message ...
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.

--
Regards,

timmulla


timmulla

looping through txt files and pasting into a excel worksheet
 
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" wrote:

Hi timmulla

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

--

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


"timmulla" wrote in message ...
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.

--
Regards,

timmulla



Ron de Bruin

looping through txt files and pasting into a excel worksheet
 
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" wrote in message ...
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" wrote:

Hi timmulla

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

--

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


"timmulla" wrote in message ...
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.

--
Regards,

timmulla



timmulla

looping through txt files and pasting into a excel worksheet
 
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.


--
Regards,

timmulla


"Ron de Bruin" wrote:

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" wrote in message ...
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" wrote:

Hi timmulla

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

--

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


"timmulla" wrote in message ...
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.

--
Regards,

timmulla



Ron de Bruin

looping through txt files and pasting into a excel worksheet
 
Change the start row

StartRow _
:=1

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


--

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


"timmulla" wrote in message ...
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.


--
Regards,

timmulla


"Ron de Bruin" wrote:

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" wrote in message ...
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" wrote:

Hi timmulla

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

--

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


"timmulla" wrote in message ...
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.

--
Regards,

timmulla




All times are GMT +1. The time now is 07:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com