#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Append text file

Hi,

I have two text files and I want to append TextFileB onto the end of TextFileA

TextFileA is 3 million rows
TextFileB is 100 rows

The problem is that TextFileA is 3 million rows long. So I do not want to
create an array, load all of TextFileA, then output TextFileA and then the
100 lines of TextFileB (that would take a long time). That is the only way I
know of to append B to the end of A.

Can anyone help?

Thanks!



  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 638
Default Append text file

How about something like this.
fNum=FreeFile
Open TextFileA For Append As fNum
Print fNum, TextFileB
Close fNum

Jeff wrote:
Hi,

I have two text files and I want to append TextFileB onto the end of TextFileA

TextFileA is 3 million rows
TextFileB is 100 rows

The problem is that TextFileA is 3 million rows long. So I do not want to
create an array, load all of TextFileA, then output TextFileA and then the
100 lines of TextFileB (that would take a long time). That is the only way I
know of to append B to the end of A.

Can anyone help?

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Append text file

Hi,

I tried the following code but go the error message "method not valid
without suitable object" on the line 'Print fNum, TextFileB'

Code:
Sub TestCode()

'How about something like this.
'fNum = FreeFile
'Open TextFileA For Append As fNum
'Print fNum, TextFileB
'Close fNum

TextFileA = "C:\IScenarioSets1.csv"
TextFileB = "C:\IScenarioSets2.csv"

fNum = FreeFile
Open TextFileA For Append As fNum
Print fNum, TextFileB
Close fNum

End Sub




"JW" wrote:

How about something like this.
fNum=FreeFile
Open TextFileA For Append As fNum
Print fNum, TextFileB
Close fNum

Jeff wrote:
Hi,

I have two text files and I want to append TextFileB onto the end of TextFileA

TextFileA is 3 million rows
TextFileB is 100 rows

The problem is that TextFileA is 3 million rows long. So I do not want to
create an array, load all of TextFileA, then output TextFileA and then the
100 lines of TextFileB (that would take a long time). That is the only way I
know of to append B to the end of A.

Can anyone help?

Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 638
Default Append text file

Give this a go.
Sub TestCode()
Dim fNum As Integer, fNum2 As Integer
Dim yourInfo As String
TextFileA = "C:\IScenarioSets1.csv"
TextFileB = "C:\IScenarioSets2.csv"
fNum = FreeFile
Open TextFileA For Append As fNum
fNum2 = FreeFile
Open TextFileB For Input As fNum2
Do While Not EOF(fNum2)
Line Input #fNum2, yourInfo
Print #fNum, yourInfo
Loop
Close #fNum
Close #fNum2
End Sub

Jeff wrote:
Hi,

I tried the following code but go the error message "method not valid
without suitable object" on the line 'Print fNum, TextFileB'

Code:
Sub TestCode()

'How about something like this.
'fNum = FreeFile
'Open TextFileA For Append As fNum
'Print fNum, TextFileB
'Close fNum

TextFileA = "C:\IScenarioSets1.csv"
TextFileB = "C:\IScenarioSets2.csv"

fNum = FreeFile
Open TextFileA For Append As fNum
Print fNum, TextFileB
Close fNum

End Sub




"JW" wrote:

How about something like this.
fNum=FreeFile
Open TextFileA For Append As fNum
Print fNum, TextFileB
Close fNum

Jeff wrote:
Hi,

I have two text files and I want to append TextFileB onto the end of TextFileA

TextFileA is 3 million rows
TextFileB is 100 rows

The problem is that TextFileA is 3 million rows long. So I do not want to
create an array, load all of TextFileA, then output TextFileA and then the
100 lines of TextFileB (that would take a long time). That is the only way I
know of to append B to the end of A.

Can anyone help?

Thanks!




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,202
Default Append text file

If your files are really **text** files as the names indicate, you can
always go "lo-tech"... start Windows command processor (Start
Button/(All)Programs/Accessories/CommandPrompt)... if your files are both in
the same directory, 'cd' to that directory, for example....

cd c:\directory1\directory2\etc.

Then execute this command (note the plus sign)...

copy TextFileA.txt+TextFileB.txt TextFileA.txt

If the files are located in different directories, then you can execute the
following command without using 'cd' first...

copy <Path\TextFileA.txt+<Path\TextFileB.txt <Path\TextFileA.txt

where you would substitute the complete path to each file where I have
indicated <Path. By the way, if you want to test this out before actually
changing TextFileA, change the last file to a non-existent filename and the
concatenated file will be written to it instead. For example, using the
first command where you used 'cd' to move to the common directory...

copy TextFileA.txt+TextFileB.txt TestFile.txt

Doing this will create a new file in the common directory and then place the
concatenated file into it. You can then see if the result is what you want
before making it permanent.

Rick


"Jeff" wrote in message
...
Hi,

I have two text files and I want to append TextFileB onto the end of
TextFileA

TextFileA is 3 million rows
TextFileB is 100 rows

The problem is that TextFileA is 3 million rows long. So I do not want to
create an array, load all of TextFileA, then output TextFileA and then the
100 lines of TextFileB (that would take a long time). That is the only
way I
know of to append B to the end of A.

Can anyone help?

Thanks!






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Append text file

Thank you both for your help on this!

"Rick Rothstein (MVP - VB)" wrote:

If your files are really **text** files as the names indicate, you can
always go "lo-tech"... start Windows command processor (Start
Button/(All)Programs/Accessories/CommandPrompt)... if your files are both in
the same directory, 'cd' to that directory, for example....

cd c:\directory1\directory2\etc.

Then execute this command (note the plus sign)...

copy TextFileA.txt+TextFileB.txt TextFileA.txt

If the files are located in different directories, then you can execute the
following command without using 'cd' first...

copy <Path\TextFileA.txt+<Path\TextFileB.txt <Path\TextFileA.txt

where you would substitute the complete path to each file where I have
indicated <Path. By the way, if you want to test this out before actually
changing TextFileA, change the last file to a non-existent filename and the
concatenated file will be written to it instead. For example, using the
first command where you used 'cd' to move to the common directory...

copy TextFileA.txt+TextFileB.txt TestFile.txt

Doing this will create a new file in the common directory and then place the
concatenated file into it. You can then see if the result is what you want
before making it permanent.

Rick


"Jeff" wrote in message
...
Hi,

I have two text files and I want to append TextFileB onto the end of
TextFileA

TextFileA is 3 million rows
TextFileB is 100 rows

The problem is that TextFileA is 3 million rows long. So I do not want to
create an array, load all of TextFileA, then output TextFileA and then the
100 lines of TextFileB (that would take a long time). That is the only
way I
know of to append B to the end of A.

Can anyone help?

Thanks!





  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 284
Default Append text file

Here is one option:

___________________________________

Sub AppendTextFile()

Const ForReading = 1
Const ForAppending = 8

Dim StrTransfer As String

txtFileAname = "C:\IScenarioSet1.csv"
txtFileBname = "C:\IScenarioSet2.csv"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set txtFileB = FSO.OpenTextFile(txtFileBname, ForReading)
StrTransfer = txtFileB.ReadAll
txtFileB.Close

Set txtFileA = FSO.OpenTextFile(txtFileAname, ForAppending)
txtFileA.Write vbCrLf & StrTransfer
txtFileA.Close

Set FSO = Nothing

End Sub

___________________________________

Steve



"Jeff" wrote in message
...
Hi,

I have two text files and I want to append TextFileB onto the end of
TextFileA

TextFileA is 3 million rows
TextFileB is 100 rows

The problem is that TextFileA is 3 million rows long. So I do not want to
create an array, load all of TextFileA, then output TextFileA and then the
100 lines of TextFileB (that would take a long time). That is the only
way I
know of to append B to the end of A.

Can anyone help?

Thanks!





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I Append values to an existing excel file. viv New Users to Excel 0 March 21st 07 11:25 AM
Append text Jeff Excel Discussion (Misc queries) 1 February 16th 07 10:28 PM
How do I append same text to all the cells in a column at once? Abhijit Bamishte Excel Worksheet Functions 4 December 15th 06 07:26 PM
append file on e-mail Sylvian Excel Discussion (Misc queries) 0 September 7th 05 07:23 PM
Append the data given in diff sheets of an Excel File to one sheet sansk_23 Excel Worksheet Functions 3 May 10th 05 02:00 AM


All times are GMT +1. The time now is 09:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"