Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how can I Append values to an existing excel file. | New Users to Excel | |||
Append text | Excel Discussion (Misc queries) | |||
How do I append same text to all the cells in a column at once? | Excel Worksheet Functions | |||
append file on e-mail | Excel Discussion (Misc queries) | |||
Append the data given in diff sheets of an Excel File to one sheet | Excel Worksheet Functions |