I have a document that has docproperties in the header and body. I have
a custom button that loads a userform in which these document
properties can be changed. Right now, I have the following code that
updates all the fields on the page:
Dim myStoryRange As Range
For Each myStoryRange In ActiveDocument.StoryRanges
myStoryRange.Fields.Update
Next myStoryRange
This works, however, I'd like to be able to ONLY update the 3 document
properties that have changed. Is there any way to do this?
>I have a document that has docproperties in the header and body. I have
> a custom button that loads a userform in which these document
[quoted text clipped - 8 lines]
> This works, however, I'd like to be able to ONLY update the 3 document
> properties that have changed. Is there any way to do this?
Dim myStoryRange As Range
Dim oField as Field
For Each myStoryRange In ActiveDocument.StoryRanges
For each oField in myStoryRange.Fields
If oField.Type = wdFieldDocProperty Then
oField.Update
End If
Next oField
Next myStoryRange

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
ernmeg@gmail.com - 02 Aug 2005 20:21 GMT
Thanks a lot Jonathan! Is there any way to avoid looping through all
the fields in the range and only update specific fields?
Jonathan West - 02 Aug 2005 20:24 GMT
> Thanks a lot Jonathan! Is there any way to avoid looping through all
> the fields in the range and only update specific fields?
If you know exactlly which fields you want, you could do it something like
this
With ActiveDocument.Range
.Fields(1).Update
.Fields(3).Update
.Fields(47).Update
End With
but that will only work if your document doesn't change to the extent of
adding or removing fields. You might be safer updating all fields of a
specific type.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
ernmeg@gmail.com - 02 Aug 2005 20:40 GMT
Ah I see, no way to access the fields by name?
Jonathan West - 02 Aug 2005 22:10 GMT
> Ah I see, no way to access the fields by name?
I suppose you you mark the field with a bookmark, and then reference the
first field in the range marked by the bookmark. Something like this.
ActiveDocument.Bookmarks("MyBookmark").Range.Fields(1).Update

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org