I am using - ActiveDocument.MailMerge.Fields
My mail merge items which appear in either text boxes,
headers or footers don't get included in a field count or
list
My test is a macro from within my document is as follows
For lngcnt = 1 To ActiveDocument.MailMerge.Fields.Count
strdict = strdict & " " & _
ActiveDocument.MailMerge.Fields(lngcnt).Code
Next lngcnt
MsgBox strdict
Any help in generating the mail merge list would be
greatly appreciated.
Dim r As Range
Dim f As Field
Dim c As Long
c = 0
For Each r In ActiveDocument.StoryRanges
For Each f In r.Fields
If f.Type = wdFieldMergeField Then
c = c + 1
End If
Next
Next
Debug.Print c
End Sub
But that would only count MERGEFIELD fields - you would need a bit more
logic if you want to include other types.
--
Peter Jamieson
MS Word MVP
"Nigel Godwin" <nig...@mis-lgs.com> wrote in message
news:00b401c2d2b9$53201770$a201...@phx.gbl...
This works except for multiple text boxes.
I cannot see how the range misses a second text box
although it does do headers footers and a first text box.
Thanks for any help
Nigel
I guess the following is a bit closer, but the WOrd object model always
seems to have some new black hole that needs exploration. In particular I
remember seeing something about textboxes in headers/footers of perhaps
fields in them not being counted properly or some such.
Sub countmergefields()
Dim r As Range
Dim f As Field
Dim c As Long
Dim s As Shape
c = 0
For Each r In ActiveDocument.StoryRanges
If r.StoryType <> wdTextFrameStory Then
For Each f In r.Fields
If f.Type = wdFieldMergeField Then
c = c + 1
End If
Next
End If
Next
For Each s In ActiveDocument.Shapes
If s.Type = msoTextBox Then
For Each f In s.TextFrame.TextRange.Fields
If f.Type = wdFieldMergeField Then
c = c + 1
End If
Next
End If
Next
Debug.Print c
End Sub
--
Peter Jamieson
MS Word MVP
"Nigel Godwin" <nig...@mis-lgs.com> wrote in message
news:02a901c2d36b$3d72f2a0$3001...@phx.gbl...