Getting the number of REF fields

C

Chris

I need a count of the cross-references in a (big) document.
ActiveDocument.Fields.Count tells me how many fields of any kind there
are, but I don't see how to narrow it to just REFs. Anyone know how to
get this?
 
J

Jay Freedman

Chris said:
I need a count of the cross-references in a (big) document.
ActiveDocument.Fields.Count tells me how many fields of any kind there
are, but I don't see how to narrow it to just REFs. Anyone know how to
get this?

Sub CountRefs()
Dim counter As Long
Dim fld As Field
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldRef Then
counter = counter + 1
End If
Next

MsgBox "There are " & counter & " REF fields"
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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