View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Cindy M -WordMVP- Cindy M  -WordMVP- is offline
external usenet poster
 
Posts: 370
Default Header / Footer mail merge issue with custom built word automation solution.

Hi Jaimie,

As I'm not performing a mail merge (there is no
document.MailMerge.DataSource) I'm assuming I will need to implement my
own custom code to emulate the
WdMailMergeDestination.wdSendToNewDocument..wdSend ToPrinter
functionality? I'm pretty sure I already know the answer.

LOLYes, in that case you do have to code it all. Question then becomes,
of course, what's the most efficient approach.

One possibility would be to close the document and start over again with
a new copy. But that would be comparatively slow.

I might be more inclined to begin by setting a BOOKMARK around each
mergefield target (do that in your loop, rather than writing in the
text).

Then loop. In the loop, write the text to Bookmark.Range.Text (which
should remove the mergefield on the first pass), and then recreate the
bookmark so that it will always be there. Very roughly, in VBA-speak:
Dim rng as Word.Range
Dim bkmName as String

Set rng = document.Bookmarks(bkmName).Range
rng.Text = "the data"
document.Bookmarks.Add Name:=bkmName, Range:=rng

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)