reading textfile into word

E

efqwf

How can i read with vba the content of multiple textfiles into a word
document. The structure is:
C:\Test\1.txt
C:\Test\2.txt
C:\Test\3.txt
C:\Test\4.txt

Can someone help me with that.

Willem
 
H

Helmut Weber

Hi,

quick and dirty,
in case there aren't more than 1000000 files to process, ;-)


Sub Test8970()
Dim l As Long
Dim s As String
On Error GoTo finish
For l = 1 To 10000000
Open "c:\test\" & CStr(l) & ".txt" For Input As 1
While Not EOF(1)
Input #1, s
ActiveDocument.Range.InsertAfter s & Chr(13)
Wend
Close #1
Next
finish:
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top