How to get mail merge fields in text boxes?

How to get mail merge fields in text boxes?

Post by RFlhbm » Thu, 22 Jul 2004 04:09:02


Hi,

I am working on a project that needs to find all the mail merge fields in a Word template. C#, Word XP InterOp, and Word XP are used in the project.

To get the mail merge fields in the main document can be done through ActiveDocument.MailMerge.Fields. It returns a collection of the codes of all mail merge fields in the active document. But it does not give you the mail merge fields inside a textbox, header, or footer.

Does any know how to get the mail merge field codes in a text box?

Thanks a lot

Daniel
 
 
 

How to get mail merge fields in text boxes?

Post by Chad DeMey » Thu, 22 Jul 2004 04:34:51

his is a multi-part message in MIME format.


DYang,

Dim s As Shape, f As Field
For Each s In ActiveDocument.Shapes
With s.TextFrame
If .HasText Then
For Each f In .TextRange.Fields
Select Case f.Type
Case wdFieldMergeField, wdFieldMergeRec, wdFieldMergeSeq
'your code here
Case Else
'your code here
End Select
Next f
End If
End With
Next

Hope that helps
Regards,
Chad


"DYang" < XXXX@XXXXX.COM > wrote in message news: XXXX@XXXXX.COM ...
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN>> < < < < < < size=>>DYang< < < <
  Dim s As Shape, f As
Fiel<  For Each s In ActiveDocument.Shape<    With
s.TextFram<      If .HasText
The<        For Each f In
..TextRange.Field<         
Select Case
f.Typ<           
Case wdFieldMergeField, wdFieldMergeRec,
wdFieldMergeSe<             
'your code
her<            Case
Els<             
'your code her<          End
Selec<        Next
<      End I<    End
Wit<  Nex< <
Hope that help< <
Regards< <
Cha< <
 < <
size=>< < <"DYang" << href="mailto: XXXX@XXXXX.COM >< size=>> XXXX@XXXXX.COM <> wrote
in message< href="news: XXXX@XXXXX.COM >< size=>>news: XXXX@XXXXX.COM < face=Arial size=>>..<> Hi<>
 <> I am working on a project that needs to find all the mail merge
fields in a Word template. C#, Word XP InterOp, and Word XP are used in the
project<><> To get the mail merge fields in the main document can
be done through ActiveDocument.MailMerg
 
 
 

How to get mail merge fields in text boxes?

Post by RFlhbm » Fri, 23 Jul 2004 08:09:02

Thanks Chad, it works great.

Daniel