Merge several fixed width text files into one

X

XP

Using Office 2003 and Windows XP; and using using VBA from MS-Excel;

1) There will be several (between 1 and 10) fixed width text files in a
specific folder, each formatted the same way; the files range from a few kb
to 100kb in size.

2) I need a program that will sequentially open each text file and copy the
contents;

3) The contents of each separate text file, along with all formatting, must
be transferred undisturbed into a new fixed width text file, appending the
contents of each text file into a new SINGLE merged text file;

I can already code the part where the list of files is captured and each may
be opened and closed. I need help with the part where the data is copied from
the text file and then written to the new single merge file. Can someone
please post some example code that would help me get started?

Should I use FileSystemObject? Or something else? Suggestions? Help?

Thanks much in advance for your assistance.
 
J

Jim Rech

Adapt this:

Sub a()
Dim SrcFiles, CurrSrc As String
Dim DestFile As String, Counter As Integer
Dim TextLine As String
SrcFiles = Array("c:\File1.txt", "c:\File2.txt")
Open "c:\file3.txt" For Output As #1
For Counter = 0 To UBound(SrcFiles)
Open SrcFiles(Counter) For Input As #2
Do While Not EOF(2)
Line Input #2, TextLine
Print #1, TextLine
Loop
Close #2
Next
Close #1
End Sub


--
Jim
| Using Office 2003 and Windows XP; and using using VBA from MS-Excel;
|
| 1) There will be several (between 1 and 10) fixed width text files in a
| specific folder, each formatted the same way; the files range from a few
kb
| to 100kb in size.
|
| 2) I need a program that will sequentially open each text file and copy
the
| contents;
|
| 3) The contents of each separate text file, along with all formatting,
must
| be transferred undisturbed into a new fixed width text file, appending the
| contents of each text file into a new SINGLE merged text file;
|
| I can already code the part where the list of files is captured and each
may
| be opened and closed. I need help with the part where the data is copied
from
| the text file and then written to the new single merge file. Can someone
| please post some example code that would help me get started?
|
| Should I use FileSystemObject? Or something else? Suggestions? Help?
|
| Thanks much in advance for your assistance.
 

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