How to limit a COUNT of fields to First page

E

ES

I have some code working perfectly that loops through each "Range in
ActiveDocument.StoryRanges", each "Shape in ActiveDocuments.Shapes", and
each "HeaderFooter in Section.Header" to find the count of MailMergeFields
in a document. The problem is, I now want to limit this search to find
fields on the first page only and not the entire document (if multiple
pages). Therefore, I simply need to wrap this code around code that only
searches if the active page = first page. I'm not sure how to determine the
first page and only search for the fields on the first page.

Thanks,
Enoch
 
D

Doug Robbins - Word MVP

Hi Enoch,

Use:

Dim af As Field, i As Integer
i = 0
Selection.HomeKey wdStory
For Each af In Selection.Bookmarks("\page").Range.Fields
If af.Type = wdFieldMergeField Then
i = i + 1
End If
Next af
MsgBox "There are " & i & " mergefields on the first page."

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
E

ES

That did it! Thanks.

ES


Doug Robbins - Word MVP said:
Hi Enoch,

Use:

Dim af As Field, i As Integer
i = 0
Selection.HomeKey wdStory
For Each af In Selection.Bookmarks("\page").Range.Fields
If af.Type = wdFieldMergeField Then
i = i + 1
End If
Next af
MsgBox "There are " & i & " mergefields on the first page."

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top