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 / July 2007

Tip: Looking for answers? Try searching our database.

Updating fields with a macro?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed from AZ - 13 Jul 2007 17:30 GMT
I have some StyleRef fields and a TOC field that I would like to
update using a macro.  I ran a macro to Debug.Print all field types
and results to see which ones I need.

It looks like my StyleRef fields are type 10 - but it also looks like
the macro didn't see the fields in the headers.  So I need to run the
FieldUpdate twice - once in the doc body and once in the header story?

The TOC seemed to be comprised of three different types of fields: 13
gives me all the text, 88 gives me each individual line of text, and
37 gives me the page number.  Might the 88 and 37 fields be
hyperlinks?  I only want to update the page numbers.  I tried
recording a macro for this and got only
  Selection.Fields.Update
which I'm afraid may update more than just the page numbers.

Does anyone have any insight into doing this?

Ed
Russ - 13 Jul 2007 20:03 GMT
Ed,

From VBA Help:
UpdatePageNumbers Method
Updates the page numbers for items in the specified table of contents or
table of figures.
Syntax
expression.UpdatePageNumbers
expression   Required. An expression that returns a TableOfContents or
TableOfFigures object.

This could be amended to update only certain stories.
Search for the word Story in the object browser (In View menu) in VBA Editor
to see all the stories available.

Sub UpdateAllFields()
Dim oStory As Range
 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

> I have some StyleRef fields and a TOC field that I would like to
> update using a macro.  I ran a macro to Debug.Print all field types
[quoted text clipped - 15 lines]
>
> Ed

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Ed from AZ - 13 Jul 2007 21:46 GMT
Thanks, Russ.  I didn't even think to check on a TableofContents being
a separate type of object.  I had the thought that it had to be a
certain kind of field.  Thank you for the boost and the code.

Ed

On Jul 13, 12:03 pm, Russ <drsN0SPAMmi...@hotmailD0Tcom.INVALID>
wrote:
> Ed,
>
[quoted text clipped - 51 lines]
>
> - Show quoted text -
Russ - 13 Jul 2007 22:12 GMT
Ed,
You're Welcome.
I'm not sure who the author was for the code, its been out there for awhile.

> Thanks, Russ.  I didn't even think to check on a TableofContents being
> a separate type of object.  I had the thought that it had to be a
[quoted text clipped - 59 lines]
>>
>> - Show quoted text -

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
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.