View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Myrna Larson Myrna Larson is offline
external usenet poster
 
Posts: 863
Default Concatenate Text File

No, there's no single command to do that. However, if the 2nd file is less
than the maximum allowed for a single string (2^31 bytes), you can do this:

File1 = "FirstFile.Txt"
File2 = "SecondFile.Txt"

Open File1 For Binary As #1
Seek #1, LOF(1) + 1
Open File2 For Binary AS #2
X = Space$(LOF(2))
Get #2, 1, X
Put #1, , X
Close #1, #2

If it's binary data and too big to read into a single string, you would have
to read in blocks, most probably adjusting the size of the the string variable
when reading the last block. IOW, you would have to keep track of the number
of bytes left, and if it's less than the length of X, redefine X to the number
of bytes left before the last Get statement.

If the 2nd file is too large, and it consists of lines ending with CR/LF, you
can do it the old fashioned way:

File1 = "FirstFile.Txt"
File2 = "SecondFile.Txt"
Open File1 For Append As #1
Open File2 For Input AS #2
Do While Not EOF(2)
Line Input #2, X
Print #1, X
Loop
Close #1, #2



On Tue, 19 Oct 2004 10:06:35 -0500, RickKennedy
wrote:


Are you saying there is not a command to contatenate two text files in
VBA?