Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

MS Word VBA - update specific docproperty

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ernmeg@gmail.com - 02 Aug 2005 18:47 GMT
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?
Jonathan West - 02 Aug 2005 20:03 GMT
>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 

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.