Jay
Wed Nov 01 11:58:09 CST 2006
If you want to do it this way, you have to collect the lines as they're read
from the file and append them to a string:
Dim tempString, MyString
Open "C:\files\test.txt" For Input As #1
Do While Not EOF(1)
Input #1, tempString
MyString = MyString & tempString & vbCr
Loop
Close #1
' remove last vbCr
MyString = Left(MyString, Len(MyString) - 1)
ActiveDocument.Bookmarks("Test").Range.Text = MyString
But you can do the whole thing in one step with the InsertFile command:
ActiveDocument.Bookmarks("Test").Range.InsertFile _
FileName:="c:\files\test.txt"
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
aef1@lycos.co.uk wrote:
> Please would someone know how to enter text from a text file (the
> whole file contents) into Word. I have seen some code on the forums,
> but don't understand how it works.
>
> Found this simple code, but it will only input the last set of
> characters in the file.
>
>
> Dim MyString
> Open "C:\files\test.txt" For Input As #1
> Do While Not EOF(1)
> Input #1, MyString
> Loop
> Close #1
>
>
> ActiveDocument.Bookmarks("Test").Range.Text = MyString
>
>
> Thanks in advance,
> Net