Append a range to the end of another document

H

Hotwheels

I need to know how to take a range of a section of one document and append it
to the end of another document . I have an example subroutine that I have
been testing with that shows my problem. See *** below. Do I need too move
my selection in the second document to the end and how do I put the text in
the range from the first document at that place?

Mike

Private Sub MergeASection(iSection As Integer)
Dim oWrd As Word.Application
Dim oMergeDoc As Word.Document
Dim oDoc As Word.Document
Dim oNewDoc As Word.Document
Dim oRange As Word.Range

Set oWrd = CreateObject("Word.Application")
Set oDoc = oWrd.Documents.Open("c:\mikestest\TempTemplate.doc")
Set oNewDoc = oWrd.Documents.Open("c:\mikestest\NewDoc.doc")
oDoc.MailMerge.MainDocumentType = wdFormLetters
oDoc.MailMerge.OpenDataSource Name:="c:\mikestest\data2.dat"
oWrd.Visible = True
oWrd.Activate
Screen.MousePointer = vbDefault
oDoc.MailMerge.Destination = wdSendToNewDocument
oDoc.MailMerge.Execute
Set oMergeDoc = oWrd.ActiveDocument
Set oRange = oMergeDoc.Sections(iSection).Range
oRange.End = oRange.End - 1

*** 'Need to know how to append oRange into the end of oNewDoc here

oNewDoc.Saved
oNewDoc.Close
oMergeDoc.Saved = True
oMergeDoc.Close
oDoc.MailMerge.MainDocumentType = wdNotAMergeDocument
oDoc.Save
oDoc.Close
oWrd.Quit

Set oMergeDoc = Nothing
Set oDoc = Nothing
Set oWrd = Nothing
End Sub
 
L

Leigh Webber

The easiest way to do this is to use the clipboard:

oRange.Copy
oNewDoc.Bookmarks("\EndOfDoc").Range.Paste

This clobbers your clipboard, of course, so be careful. If you take over the
clipboard inside your code, the user may experience strange things. E.g. if
the user copies some text, then runs your macro, then tries to paste their
text, they will instead paste whatever *your code* copied internally. You
can overcome this with more complex coding if necessary.
 

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