ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Concatenate Text File (https://www.excelbanter.com/excel-programming/314002-concatenate-text-file.html)

RickKennedy[_2_]

Concatenate Text File
 

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

--
RickKenned
-----------------------------------------------------------------------
RickKennedy's Profile: http://www.excelforum.com/member.php...fo&userid=1541
View this thread: http://www.excelforum.com/showthread.php?threadid=27029


Tom Ogilvy

Concatenate Text File
 
shell("copy master.txt + file1.txt file2.txt")

--
Regards,
Tom Ogilvy

"RickKennedy" wrote in message
...

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


--
RickKennedy
------------------------------------------------------------------------
RickKennedy's Profile:

http://www.excelforum.com/member.php...o&userid=15419
View this thread: http://www.excelforum.com/showthread...hreadid=270290




Myrna Larson

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?




All times are GMT +1. The time now is 05:47 AM.

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