Link to home
Start Free TrialLog in
Avatar of FaheemAhmadGul
FaheemAhmadGulFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Inserting Text From Another Word Document

I would like to insert text into my currently open word document from another word document on one of my hard disk through the click event of a Button on my Form.
The following line of code does this for me.

Private Sub BringText_Click()

ChangeFileOpenDirectory "G:\My Folder\"
    Selection.InsertFile fileName:="Test Document.doc", Range:="", _
        ConfirmConversions:=False, Link:=False, Attachment:=False
End Sub

However the above code brings the whole of the Text Document into my Word Document. I would like to modify the above code such that it brings only the first paragraph from the "Test Document" into my currently open Word Document. I would appreciate your help with this. Thanks.

Private Sub BringText_Click()

ChangeFileOpenDirectory "G:\My Folder\"
    Selection.InsertFile fileName:="Test Document.doc", Range:="", _
        ConfirmConversions:=False, Link:=False, Attachment:=False
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Otherwiae you could open it and do a copy and paste
Private Sub BringText_Click()
    Dim doc As Word.Document
    
    Set doc = Documents.Open("G:\My Folder\Test Document.doc")
    doc.Paragraphs(1).Range.Copy
    Selection.Paste
    doc.Close wdDoNotSaveChanges
End Sub

Open in new window

Avatar of FaheemAhmadGul

ASKER

Many thanks. My apologies for the delay in accepting the solution. I did not realise it has been posted because this time I did not receive any email to let me know that a comment has been posted on my question on the forum.