The StoryRange collection structure is pretty weird (in fact, it's weirder
than I'd realised). You need something like:
Sub sad()
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
Debug.Print oStory.StoryType
oStory.Fields.Unlink
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
Debug.Print oStory.StoryType
oStory.Fields.Unlink
Wend
Next
However, that might not be the final word...
> Dim Status as Integer
> Status = ActiveDocument.Fields.Update
[quoted text clipped - 6 lines]
> will not compile, with the message " Expected Function or Variable". I also
> get the same compile time error with the ToggleShowCodes method.
The reason for this is that Update is a "Function" (i.e. with a result) and
Unlink is a "Sub". Although the VBA Help does not (or did not) usually
distinguish explicitly whether a method is one or the other, you will
usually find documentation on any results returned. The Object Browser is
sometimes helpful for this kind of thing too. FWIW Word VBA Help says the
following about the return value of Update:
Field or Fields object: Updates the result of the specified object. When
applied to a Field object, returns True if the field is updated
successfully. When applied to a Fields collection, returns 0 (zero) if no
errors occur when the fields are updated, or returns the index of the first
field that contains an error.

Signature
Peter Jamieson
> OK, so it seems that the HeaderFooters collection is contained by the Section
> object, but is not contained by the StoryRanges collection. So iterating over
[quoted text clipped - 102 lines]
> > > >
> > > > Thanks for your help with this problem.
Ken - 19 Oct 2004 17:41 GMT
Peter,
This is the code that does the job for me.
Sub UnlinkAllSections()
Dim oSection As Section
Dim I, intSectionCount As Integer
intSectionCount = ActiveDocument.Sections.Count
For I = 1 To intSectionCount
ActiveDocument.Sections(I).Range.Fields.Unlink
ActiveDocument.Sections(I).Headers.Item
(wdHeaderFooterPrimary).Range.Fields.Unlink
ActiveDocument.Sections(I).Footers.Item(wdHeaderFooterPrimary).Range.Fields.Unlink
Next
End Sub
It just unlinks the section range, then attacks the individual
headers/footers in the section. I wish I knew how to iterate over the
HeaderFooter collection, but couldn't quite get it. Maybe it has something to
dio with collections that have fixed index values predefined as constants.
Anyway this works for me.
Many thanks for your great help.
Ken
> The StoryRange collection structure is pretty weird (in fact, it's weirder
> than I'd realised). You need something like:
[quoted text clipped - 172 lines]
> > > > >
> > > > > Thanks for your help with this problem.
Peter Jamieson - 19 Oct 2004 18:31 GMT
OK, thanks for the feedback.

Signature
Peter Jamieson
> Peter,
>
[quoted text clipped - 8 lines]
> ActiveDocument.Sections(I).Headers.Item
> (wdHeaderFooterPrimary).Range.Fields.Unlink
ActiveDocument.Sections(I).Footers.Item(wdHeaderFooterPrimary).Range.Fields.
Unlink
> Next
> End Sub
[quoted text clipped - 186 lines]
> > > > > >
> > > > > > Thanks for your help with this problem.