View Single Post
  #7   Report Post  
Charles Kenyon
 
Posts: n/a
Default

Thank you. I seldom work with mulit-section documents and so didn't trip
over this.


--

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://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
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.

"Jezebel" wrote in message
...
Charles, there are bugs in your code --

1) Currently you are updating fields only in the body of the document,
notwithstanding your loop through the StoryRanges.

For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular
document
For Each oField In ActiveDocument.Range.Fields -----
This is wrong

The line should be --

For Each oField In oStory.Fields


2) But even fixing that, your code will also miss fields in headers and
footers after the first section, and in textframes after the first.
Header/Footer and Textframe StoryRanges are linked lists. Iterating the
StoryRanges collection returns only the first item in the list. To get the
subsequent ranges you need something like

For Each oStory In ActiveDocument.StoryRanges

Do
oStory.Fields.Update
set oStory = oStory.Next
Loop until oStory is nothing

Next


Also there's no need to iterate the fields themselves. Once you have the
range you can operate on all its fields in one statement:

oStory.Fields.Update, oStory.field.unlink, etc




"Charles Kenyon" wrote in
message ...
What follows is code that works to update all REF fields in a document. I
know that works. Then I am giving you code that I expect will do what you
want based on the macro I've tested.

Sub RefFieldUpdateAllStory()
' Written by Charles Kyle Kenyon 15 November 2001
' All Story Field Updater - Ref fields
Dim oField As Field
Dim oStory As Range
On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
For Each oField In ActiveDocument.Range.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Next oStory
End Sub

Sub FieldsUnlinkAllStory()
' Written by Charles Kyle Kenyon 9 December 2004
' All Story Field Unlinker
Dim oField As Field
Dim oStory As Range
On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
' This goes into headers and footers as well as the regular document
For Each oField In ActiveDocument.Range.Fields
oField.Unlink
Next oField
Next oStory
End Sub

There may be something less complex that will do it. If you don't have
headers/footers, text boxes or frames that contain fields you could just
use:

ActiveDocument.Fields.Unlink

Hope this helps,
--

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://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
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.

"Thomas Payne" wrote in message
...
I'm running XP Pro, and Word 2002.

My publisher needs me to convert my field results to hard text. Isn't
there a macro that does this? (I don't mean just F9 switching between
viewing the field and viewing the result -- I need to eliminate all the
fields, converting them into plain text that corresponds to their
results).

On a related note: is there a macro that converts automatic numbering
to
text numbering?

Thanks for any help.
Tom