Working through all stories

B

Bear

Hello:

I have a question about this code:

Sub RefFieldUpdateAllStory()
' Written by Charles Kyle Kenyon 15 November 2001
' repaired with help from Jezebel 10 December 2004
' All Story Field Updater - Ref fields
Dim oField As Field
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
End Sub

I'm curious about the Do ... Until oStory Is Nothing loop. Isn't this
functionality inherent in the For Each oStory loop?

I mean, wouldn't this work?

Sub RefFieldUpdateAllStory()

Dim oField As Field
Dim oStory As Range

For Each oStory In ActiveDocument.StoryRanges
For Each oField In oStory.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Next oStory

End Sub

I'd really like to know...

Bear
 
J

Jean-Guy Marcil

Bear was telling us:
Bear nous racontait que :
Hello:

I have a question about this code:

Sub RefFieldUpdateAllStory()
' Written by Charles Kyle Kenyon 15 November 2001
' repaired with help from Jezebel 10 December 2004
' All Story Field Updater - Ref fields
Dim oField As Field
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
End Sub

I'm curious about the Do ... Until oStory Is Nothing loop. Isn't this
functionality inherent in the For Each oStory loop?

I mean, wouldn't this work?

Sub RefFieldUpdateAllStory()

Dim oField As Field
Dim oStory As Range

For Each oStory In ActiveDocument.StoryRanges
For Each oField In oStory.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Next oStory

End Sub

I'd really like to know...

The test it out yourself!

Try both versions it with a simple document, then again with a document with
different odd/even/first page headers/footers in multiple sections....

Then, *after* you have tested it, check out this page in case you need more
info:
http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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