Header/Footers COunting Fields

R

Rick

Is it possible to count the number of fields in a header or footer?

If so, is it then possible to access them like and index e.g.
header.field.item(i) etc or not?

Replies in jscript if possible.

Thanks
 
R

Rick

Thanks but I didn't find them much use.

I have 4 fields inside a header, 15 in the document and one in the footer.
At the moment I'm using WordDoc.Fields.Count to get the number and loop thru
each field BUT it only loops thru the main document ignoring the fields
within the header and footer.

I would like it to take these extra fields into account. I've tried looping
thru the header, then the document, then the footer but it returns 0 (zero)
for the number of fields in the header and 0 for the footer. I have also
tried to access each field directly using jscript but haven't managed to do
so.

It is as if they are invisible to the main application.

Is there a way of (i) getting to access the fields or (ii) get the fields
included in the main loop, WordDoc.Fields.Count or (iii) another easier way
to do this?

Any help greatly appreciated.
 
C

Charles Kenyon

What follows is a macro to unlink all fields in a document, cycling through
the storyranges. You should be able to adapt it to your use, incrementing a
variable with the fields.count from each story.

Sub FieldsUnlinkAllStory()
' All Story Field Unlinker
' Written by Charles Kyle Kenyon 9 December 2004
' repaired with help from Jezebel 10 December 2004
Dim oStory As Range
On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
Do
oStory.Fields.Unlink
Set oStory = oStory.NextStoryRange
Loop Until oStory Is Nothing
Next
End Sub


--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
G

Greg Maxey

Here's your fish:

Sub CountAllFields()
Dim pRange As Word.Range
Dim oFld As Field
Dim iLink As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim l As Long
iLink = ActiveDocument.Sections(1).Headers(1).Range.StoryType
For Each pRange In ActiveDocument.StoryRanges
Do
Select Case pRange.StoryType
Case 1 'The Main text
i = pRange.Fields.Count
Case 6, 7, 10
j = j + pRange.Fields.Count
Case 8, 9, 11
k = k + pRange.Fields.Count
Case Else
l = l + pRange.Fields.Count
End Select
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
MsgBox "There are " & i & " fields in the main text."
MsgBox "There are " & j & " fields in the headers."
MsgBox "There are " & k & " fields in the footers."
MsgBox "There are " & l & " fields in the other places."
MsgBox "There are " & i + j + k + l & " fields total."
End Sub
 
G

Greg Maxey

Now that I have been duly sworn , it is chr(13) and chr(7). Select an
empty cell and run the following code:

Sub Test()
MsgBox Asc(Selection.Text) _
& " and " & Asc(Right(Selection.Text, 1))
End Sub
 

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