ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Help me with MS Word styles

<< < (8/14) > >>

superboyac:
Heh...yeah.

Quick problem/question:
I'm writing my manual right now, and I cannot figure out to make a macro that will update ALL the fields, especially the table of contents...all in one click.  I've scoured the web, and used all the things they say to try, but none of them work.

It's very simple.  To update everything, you have to press Ctrl-A (to select all) and then F9 (to update).  But a dialog comes up asking if you want to update the entire table or just the page numbers.  So I select the entire table, and that's it.  That works fine.

but I'm trying to make that a macro and it won't work.  I recorded the whole process, and that didn't work.  Then I used a code I found on the web, which they say works, but it doesn't for me:

--- Code: Visual Basic ---Sub UpdateAllFields()Dim oStory As RangeDim oField As Field  For Each oStory In ActiveDocument.StoryRanges    For Each oField In oStory.Fields      oField.Update    Next oField  Next oStoryEnd Sub
If anyone can help me, please advise.  Thank you.

EDIT:
I found the following code, and it works for the table of contents.  I don't know if it works fro all fields of all type, but it works for the TOC, so I'm happy for now:

--- Code: Visual Basic ---Sub UpdateAllTOCs()For Each toc In ActiveDocument.TablesOfContentstoc.UpdateNext tocEnd Sub

kfitting:
Hmmm... dont know.  I have extensive Excel VBA experience, and minimal Word.  However, I would look at what Ranges are in Word.  By cycling through them you may be limiting your search too much.  This link may help... dont know: Word Object Model

superboyac:
Hmmm... dont know.  I have extensive Excel VBA experience, and minimal Word.  However, I would look at what Ranges are in Word.  By cycling through them you may be limiting your search too much.  This link may help... dont know: Word Object Model
-kfitting (May 14, 2010, 04:16 PM)
--- End quote ---
I have no idea what you're talking about, and i don't understand the article.  Is this in reference to my update all fields issue above?  Are you saying the code I posted doesn't work?  All i know is that I tried several things, and that last one is the only one that worked.  Do you have anything better, or do you see a problem with it?

daddydave:
I found the following code, and it works for the table of contents.  I don't know if it works fro all fields of all type, but it works for the TOC, so I'm happy for now:

--- Code: Visual Basic ---Sub UpdateAllTOCs()For Each toc In ActiveDocument.TablesOfContentstoc.UpdateNext tocEnd Sub-superboyac (May 14, 2010, 03:42 PM)
--- End quote ---
Good for you. I actually gave it a shot and I couldn't get anything to work including this code which is supposed to work according to the help file. I hate VBA.

--- Code: Visual Basic ---ActiveDocument.Fields.Update

superboyac:
daddydave, mine worked for me, but I'm using Word 2007.  I'm not sure what version you are using.  I know some of the articles I came across were written a few years ago, and they don't always specify what versions of Word they are using.  There are also issues with macro settings and security to consider.  In my limited experience, the options interface for Word (and Office 20070 is a mess.  Too many random places to change stuff.  it's not logical or intuitive at all.  You have a window, then a tab on the side for customize, then you go there, and there's another button labeled "customize" to edit keyboard shortcuts.  Geez.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version