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.
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"