Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Header/Footers COunting Fields

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick - 15 May 2006 11:00 GMT
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
Greg Maxey - 15 May 2006 11:05 GMT
Yes,

See:  http://gregmaxey.mvps.org/Field_Macros.htm for some macros that you
can adapt to this purpose.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Is it possible to count the number of fields in a header or footer?
>
[quoted text clipped - 4 lines]
>
> Thanks
Rick - 15 May 2006 14:28 GMT
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.

> Yes,
>
[quoted text clipped - 9 lines]
> >
> > Thanks
Charles Kenyon - 15 May 2006 15:10 GMT
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

Signature

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

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!

My criminal defense site: http://addbalance.com
--------- --------- --------- --------- --------- ---------
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.

> Thanks but I didn't find them much use.
>
[quoted text clipped - 35 lines]
>> >
>> > Thanks
Greg Maxey - 15 May 2006 15:13 GMT
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
Greg Maxey - 16 May 2006 04:12 GMT
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

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Thanks but I didn't find them much use.
>
[quoted text clipped - 36 lines]
>>>
>>> Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.