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
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