That was great!! thank you very much.
I used excel for that macro and then imported it into word.
Now, I have got another text file where I would like to get a specific
amount of lines but I want to specify the starting point and length.
I would be much grateful.
Regards,
NIkos
Hi Nikos,
>That was great!! thank you very much.
feels good to read.
>I used excel for that macro and then imported it into word.
You don't need Excel.
The code should work from any Office-application.
>Now, I have got another text file where I would like to get a specific
>amount of lines but I want to specify the starting point and length.
Like this, which I did not test a million times.
You have to take care yourself of attempted reading
over the end of file or of invalid arguments passed
to ReadFromTextFile.
Error handling is usually more difficult than
putting up some code that works in principle.
' ----------------------------
Sub ReadFromTextFile(lStart As Long, lNumb As Long)
Dim sTmp As String ' a temporary string
Dim lTmp As Long ' a temporary long
Open "c:\test\text\largefile.txt" For Input As #1
Open "c:\test\text\smallfile.txt" For Output As #2
For lTmp = 1 To lStart - 1
Line Input #1, sTmp
Next
For lTmp = lStart To lNumb
Line Input #1, sTmp
Print #2, sTmp
Next
Close #1
Close #2
End Sub
' ----------------------------
Sub TestRead()
Call ReadFromTextFile(10, 90)
Documents.Open "c:\test\text\smallfile.txt"
End Sub
Note that with arguments 10, 90 you get 91 paragraphs.
A minus 1 somewhere in the code might solve that.
Or use 89 if you want to get 90 paragraphs. :-)

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
nik - 17 Nov 2006 11:35 GMT
Hi Helmut,
I did the follow:-
Sub ReadFromTextFile(lStart As Long, lNumb As Long)
Dim sTmp As String ' a temporary string
Dim lTmp As Long ' a temporary long
Open "c:\test\output.txt" For Input As #1
Open "c:\test\smallfile.txt" For Output As #2
For lTmp = 1 To lStart - 1
Line Input #1, sTmp
Next
For lTmp = lStart To lNumb
Line Input #1, sTmp
Print #2, sTmp
Next
Close #1
Close #2
End Sub
------------------------------------
Sub ReadFromTextFile1(lStart As Long, lNumb As Long)
Dim sTmp As String ' a temporary string
Dim lTmp As Long ' a temporary long
Open "c:\test\output.txt" For Input As #1
Open "c:\test\smallfile1.txt" For Output As #2
For lTmp = 1 To lStart - 1
Line Input #1, sTmp
Next
For lTmp = lStart To lNumb
Line Input #1, sTmp
Print #2, sTmp
Next
Close #1
Close #2
End Sub
------------------------
Sub TestRead()
Call ReadFromTextFile(1, 90)
Call ReadFromTextFile1(91, 200)
End Sub
It is working fine!! I will double check it later but up to now it is seems
ok to me.
You are a star!!
thank you!!
> Hi Nikos,
>
[quoted text clipped - 40 lines]
> A minus 1 somewhere in the code might solve that.
> Or use 89 if you want to get 90 paragraphs. :-)