H
Hotwheels
When I do Sections.First.Range.Copy and then do a paste into a new document,
I get an extra page at the end of the new document. The template has two
pages, the merged document has two pages, but the new document gets three
pages. I also noticed that it has two sections? I tried the same code with
a simple document and did the same copy and paste without a merge and only
two pages came over and one section. How can I get rid of this second
section?
Why am I creating two sections when I do a merge and a copy and paste?
Mike
Dim oWrd As Object
Dim oMergeDoc As Object
Dim oDoc As Object
Set oWrd = CreateObject("Word.Application")
Set oDoc = oWrd.Documents.Open("c:\mikestest\TempTemplate.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
oMergeDoc.Sections.First.Range.Copy
oMergeDoc.Activate
oWrd.Documents.Add
oWrd.Selection.Paste
oWrd.ActiveDocument.SaveAs FileName:="c:\mikestest\mikestest2"
oWrd.ActiveDocument.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
I get an extra page at the end of the new document. The template has two
pages, the merged document has two pages, but the new document gets three
pages. I also noticed that it has two sections? I tried the same code with
a simple document and did the same copy and paste without a merge and only
two pages came over and one section. How can I get rid of this second
section?
Why am I creating two sections when I do a merge and a copy and paste?
Mike
Dim oWrd As Object
Dim oMergeDoc As Object
Dim oDoc As Object
Set oWrd = CreateObject("Word.Application")
Set oDoc = oWrd.Documents.Open("c:\mikestest\TempTemplate.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
oMergeDoc.Sections.First.Range.Copy
oMergeDoc.Activate
oWrd.Documents.Add
oWrd.Selection.Paste
oWrd.ActiveDocument.SaveAs FileName:="c:\mikestest\mikestest2"
oWrd.ActiveDocument.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