B
Barry555
I have code that works, but that I'm trying to improve!
My Access application generates lots of letters (using a Word template with
bookmarks), and puts these in one separate Word document so the end user can
preview it before printing. The following code does this:
With objDoc.Application.Selection
.WholeStory
.Expand (1) 'wdMainTextStory
.Copy
End With
With objMasterDoc
With .Paragraphs(.Paragraphs.Count).Range
.Collapse Direction:=0 'wdCollapseEnd
.InsertParagraphAfter
.InsertBreak Type:=2 'wdSectionBreakNextPage
End With
With .Sections(.Sections.Count)
.Footers(1).LinkToPrevious = False 'wdHeaderFooterPrimary
.Range.PasteAndFormat (0) 'wdPasteDefault
End With
End With
This works fine, but the following method works 20% quicker:
With objMasterDoc.Range
.Collapse Direction:=0 'wdCollapseEnd
.InsertParagraphAfter
.InsertBreak Type:=2 'wdSectionBreakNextPage
.FormattedText = objDoc.Content.FormattedText
End With
With objMasterDoc.Sections(objMasterDoc.Sections.Count)
.Footers(1).LinkToPrevious = False 'wdHeaderFooterPrimary
End With
This second method is fine when there are no bookmarks in the header or
footer - the header and footer text is copied over into the MasterDoc. If
there are bookmarks in the header and footer, then no text (or data inserted
at the bookmarks) from the header and footer is copied into the MasterDoc -
only the text outside of the header and footer is copied.
Where have I gone wrong?!
Barry
My Access application generates lots of letters (using a Word template with
bookmarks), and puts these in one separate Word document so the end user can
preview it before printing. The following code does this:
With objDoc.Application.Selection
.WholeStory
.Expand (1) 'wdMainTextStory
.Copy
End With
With objMasterDoc
With .Paragraphs(.Paragraphs.Count).Range
.Collapse Direction:=0 'wdCollapseEnd
.InsertParagraphAfter
.InsertBreak Type:=2 'wdSectionBreakNextPage
End With
With .Sections(.Sections.Count)
.Footers(1).LinkToPrevious = False 'wdHeaderFooterPrimary
.Range.PasteAndFormat (0) 'wdPasteDefault
End With
End With
This works fine, but the following method works 20% quicker:
With objMasterDoc.Range
.Collapse Direction:=0 'wdCollapseEnd
.InsertParagraphAfter
.InsertBreak Type:=2 'wdSectionBreakNextPage
.FormattedText = objDoc.Content.FormattedText
End With
With objMasterDoc.Sections(objMasterDoc.Sections.Count)
.Footers(1).LinkToPrevious = False 'wdHeaderFooterPrimary
End With
This second method is fine when there are no bookmarks in the header or
footer - the header and footer text is copied over into the MasterDoc. If
there are bookmarks in the header and footer, then no text (or data inserted
at the bookmarks) from the header and footer is copied into the MasterDoc -
only the text outside of the header and footer is copied.
Where have I gone wrong?!
Barry