Private Sub Command1_Click()
Dim sTargetFile As String
Dim sSourceFile As String
sTargetFile = "C:\Temp\Test.txt"
sSourceFile = "C:\Temp\Test1.txt"
Call AppendFile(sTargetFile, sSourceFile)
sSourceFile = "C:\Temp\Test2.txt"
Call AppendFile(sTargetFile, sSourceFile)
End Sub
Private Sub AppendFile(TargetFile As String, SourceFile As String)
Dim iTargetFile As Integer
Dim iSourceFile As Integer
Dim sBuffer As String
Dim lLen As Long
Dim lLoop As Long
Dim lCutPoint As Long
iSourceFile = FreeFile
Open SourceFile For Input As iSourceFile
sBuffer = Input$(LOF(iSourceFile), iSourceFile)
Close iSourceFile
lLen = Len(sBuffer)
lCutPoint = lLen
For lLoop = lLen To 1 Step -1
If Asc(Mid$(sBuffer, lLoop, 1)) > 31 Then
lCutPoint = lLoop
Exit For
End If
Next
iTargetFile = FreeFile
Open TargetFile For Append As iTargetFile
Print #iTargetFile, Left$(sBuffer, lCutPoint) & vbCrLf
Close #iTargetFile
End Sub
'===============
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep it in the groups..
"jack" <jgp...@wi.rr.com> wrote in message
news:oKOVb.32158$2h....@twister.rdc-kc.rr.com...
> Hi;
>
> I am having some trouble in getting to append anywhere from 2 to 50 text
> files. These appended files will be imported into an Excel 2002
> Workbook/Worksheet.
>
> I tried a couple of programs on several sites, but none work or are
> scripting files, which I would rather not use. On the code I did, I keep
> getting a String out of space error. Or - Bad file name or Open already.
> It's been a couple of years since I did any serious programm--I'm kinda
> rusty
>
> Is there anybody who has done this that can advise me
>
> TIA -- Jack
> P.S. I got the opening of a Spreadsheet to work fine and am able to get the
> info into the cells.
>
>
Private Sub AppendFile(TargetFile As String, SourceFile As String)
Dim TotalFile As String
Dim FileNum As Integer
FileNum = FreeFile
Open SourceFile For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
FileNum = FreeFile
Open TargetFile For Append As #FileNum
Print TotalFile & vbNewLine
Close #FileNum
End Sub
Rick - MVP
If I use the second method I get a out of memory error. I have 2Gbytes
of memory on my system(Thats Gigabytes!) and find it hard to believe
this error.
What do I do next.
Please advise.
Jack
"Rick Rothstein" <rickNOS...@NOSPAMcomcast.net> wrote in message
news:%23DI01vz...@tk2msftngp13.phx.gbl...
Thanks alot Guys!!! -- Knew it had to be me
Jack
"jack" <jgp...@wi.rr.com> wrote in message
news:H76Wb.33434$2h.2...@twister.rdc-kc.rr.com...