
Accessing a mailmerge field from vba
At what point in the merge process are you trying to execute your code? I
couldn't really work out exactly what you want to happen.
It's important to realise that there are really two types of fiedls during a
merge - the Word { MERGEFIELD } fields, which do not have a value (or
probably not the one you want) before the merge is performed, and the fields
in the data source, whose values you can get from the Mailmerge.Datasource
object.
--
Peter Jamieson
MS Word MVP
Quote:
> Hello,
> I am trying to access a field within a documents mailmerge file using
> VBA, I am not having much luck, could somebody please tell me how to
> access fields within the mailmerge file.
> The code I have is below.
> Thanks in advance.
> Selection.GoTo what:=wdGoToBookmark, Name:="bookByFax"
> If obByFax.Value = True Then
> Dim fax As String
> fax = ActiveDocument.MailMerge.Fields(19)
> Selection.TypeText "By fax " & fax
> ElseIf obConfidential.Value = True Then
> Selection.TypeText "Confidential"
> End If