Automatically update one field

A

Anni

Hi

I have the following macroes to automatically update all fields in a
document befor save and save as. But now, I want to update just one special
field, not all fields, what can I chance in macro?Please help.

Sub FileSave()
' FileSave Makro
Dim oStory As Range
ActiveDocument.Save
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
End Sub


Sub FileSaveAs()
' FileSaveAs Makro
Dim oStory As Range
Dialogs(wdDialogFileSaveAs).Show
ActiveWindow.Caption = ActiveDocument.FullName
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
End Sub
 
J

Jezebel

To update one field, you need to get a reference to it. One way is to
bookmark the range that contains it, then use

ActiveDocument.Bookmarks("MyBookmark").Range.Fields(1).Update


Separately, you can simplify your code for updating all fields --

Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
Do
oStory.Fields.Update
Set oStory = oStory.NextStoryRange
Loop until oStory is nothing
Next

Note that this doesn't quite get them all: it misses fields in textboxes
within headers and footers.
 

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