I've never really got to the bottom of this one, but if I do the following:
a. create a directory type merge using the Mail merge toolbar
b. insert a field from the data source into the body of the document,
followed by an extra paragraph mark
c. copy the field into the header
c. merge to a document
I see the field in its <<fieldname>> form
If I then click the Preview data button (the one that looks like
<< >>
ABC
) and merge again, I see one of the values of fieldname.
Clicking the Preview button is recorded as
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
Unclicking again doesn't appear to make the behaviour revert.
If you replay the recording of that lot, you get the same behaviour.
If you record you macro using the mail merge wizard, when you are setting up
the document, the wizard takes you through a task pane where you "preview
the document". It looks to me as if at this point, Word must in effect
execute
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
but it does not record it in the macro, so when you play the macro back with
a new document, you see <<fieldname>> rather than the fieldname value.
In any case, be careful when putting merge fields in headers/footers
because, in the general case you may have data from multiple data source
records on the same page: which record should Word take the header/footer
value from?
Also, you may need to look out for yet another quirk: when you merge using
the toolbar or the wizard, Word names the output document "Directoryn",
where n is a sequence number. When you merge using VBA, Word reverts to
using the old name "Catalogn".
Peter Jamieson
>I have a odd problem using Word 2002 VBA
>
[quoted text clipped - 15 lines]
>
> Any info very very gratefully recieved
Chris - 27 Oct 2006 15:53 GMT
I see what you mean , that's bizzare but any Fix is much appreciated
I had already spotted the Catalog/Directory name thing
thanks again
> I've never really got to the bottom of this one, but if I do the following:
> a. create a directory type merge using the Mail merge toolbar
[quoted text clipped - 61 lines]
> >
> > Any info very very gratefully recieved