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 / March 2008

Tip: Looking for answers? Try searching our database.

Document Refresh Macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DeanH - 28 Mar 2008 14:33 GMT
I would like a macro that did the following:
Select whole document.
F9
Update Entire Table - possibliy three times.
then Repeat once.

How do you get the Update Entire table to work for different documents that
sometimes have one Table and sometimes three Tables? Also how to repeat
process only once?

I am a very basic with macros, mainly using Record, but the recorder does
not pick up the Entire Table part of the actions (only recording
Selection.Fields.Update which does not do what is required) and does not
record the possible 3x.

Also how do you repeat process once?

Many thanks in advance.
DeanH
Graham Mayor - 28 Mar 2008 14:52 GMT
Tables? The macro used as an example at
http://www.gmayor.com/installing_macro.htm will update all the fields. If
you need to update more thoroughly then you would have to update all the
story ranges separately. You can't do this from the macro recorder.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> I would like a macro that did the following:
> Select whole document.
[quoted text clipped - 15 lines]
> Many thanks in advance.
> DeanH
DeanH - 28 Mar 2008 15:06 GMT
Thanks for the response.
Tables as in a Table of Contents, and I also have two other "TOCs", one for
List of Tables and a List of Figures, these are TOCs created from the
captions.
These three require the "Update Table of Contents" dialog to go to "Update
Entire Table" three times (if the document have three such tables in it that
is, as sometimes I only have a normal TOC).
But the Macro I am wanting should also refresh any and all other fields in
the document, ie the captions themselves and cross-referencing.
You have totally lost me with the "story ranges" mentioned.
Hope this helps.
DeanH

> Tables? The macro used as an example at
> http://www.gmayor.com/installing_macro.htm will update all the fields. If
[quoted text clipped - 20 lines]
> > Many thanks in advance.
> > DeanH
Graham Mayor - 28 Mar 2008 15:39 GMT
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

should update all the fields in your document, including the tables. It
sometimes has problems with fields in header/footer, but we can address that
if it is a problem with your document.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thanks for the response.
> Tables as in a Table of Contents, and I also have two other "TOCs",
[quoted text clipped - 43 lines]
>>> Many thanks in advance.
>>> DeanH
DeanH - 28 Mar 2008 16:18 GMT
Many thanks for this, unfortunately it still does not do the major thing I
was looking for, namely Refresh the Entire Tables.
It does update the page numbers but not the Entire Table so new Headings and
Captions are captured.
Also how do you get the macro run itself once more? So when the new Headings
and Captions are captured, their new numbers are reflected in the Tables?

Thanks again.
DeanH

Fields in Header/Footer are not a problem.

> Sub UpdateAllFields()
> Dim oStory As Range
[quoted text clipped - 61 lines]
> >>> Many thanks in advance.
> >>> DeanH
Graham Mayor - 29 Mar 2008 11:19 GMT
It should update the entire table, however if running it twice achieves
that, you can simply loop the code to run twice eg

Sub UpdateAllFields()
Dim oStory As Range
For i = 1 To 2
 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
Next i
 Set oStory = Nothing
End Sub

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Many thanks for this, unfortunately it still does not do the major
> thing I was looking for, namely Refresh the Entire Tables.
[quoted text clipped - 82 lines]
>>>>> Many thanks in advance.
>>>>> DeanH
DeanH - 31 Mar 2008 07:13 GMT
Sometimes the caption or bookmark numbering is out of sequence, say after
major shuffling, deletions and additions. Running twice ensures the tables
reflect the new order.

Unfortunately the macro still does not "Update Entire Table", only "Update
Page numbers".

For example if I copy a table caption numbered 10, then paste after - so it
will become Caption number 11. The inital number the copy has is still 10 and
also this new caption is not caputred in the List of Tables. Run the macro,
the caption is now 11, but it is still not captured in the List of Tables.
This is not to say that I copy/paste captions that much (I have a Autotext
for this) but this way clearly shows the Update Entire Table is not occuring.

Sorry to be a pain.
Thanks
DeanH

> It should update the entire table, however if running it twice achieves
> that, you can simply loop the code to run twice eg
[quoted text clipped - 101 lines]
> >>>>> Many thanks in advance.
> >>>>> DeanH
DeanH - 31 Mar 2008 07:23 GMT
Sorry got this the wrong way round. The macro IS updating the number for the
new caption and is capturing the new caption (with new number) on the List of
Tables but is not updating the numbering or name of any caption that was
previously on the List but had been edited or the numbering needs updating.
After running the macro, I do the right click Update Entire Table, all is
well, but that is what I am hoping the macro will do.

> Sometimes the caption or bookmark numbering is out of sequence, say after
> major shuffling, deletions and additions. Running twice ensures the tables
[quoted text clipped - 119 lines]
> > >>>>> Many thanks in advance.
> > >>>>> DeanH
Graham Mayor - 31 Mar 2008 07:56 GMT
When all else fails - a little brute force is needed ;) See how you get on
with the following.

Sub Update()
Dim oField As Field
Dim oStory As Range
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
Dim oTOC As TableOfContents
Dim oTOF As TableOfFigures
Dim oTOA As TableOfAuthorities
For Each oTOC In ActiveDocument.TablesOfContents
       oTOC.Update
   Next oTOC
For Each oTOF In ActiveDocument.TablesOfFigures
       oTOF.Update
   Next oTOF
For Each oTOA In ActiveDocument.TablesOfAuthorities
       oTOA.Update
   Next oTOA
For Each oStory In ActiveDocument.StoryRanges
   For Each oField In oStory.Fields
       oField.Update
   Next oField
Next oStory
For Each oSection In ActiveDocument.Sections
   For Each oHeader In oSection.Headers
       If oHeader.Exists Then
           For Each oField In oHeader.Range.Fields
               oField.Update
           Next oField
       End If
   Next oHeader
   For Each oFooter In oSection.Footers
       If oFooter.Exists Then
            For Each oField In oFooter.Range.Fields
                oField.Update
           Next oField
       End If
   Next oFooter
Next oSection
End Sub

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Sorry got this the wrong way round. The macro IS updating the number
> for the new caption and is capturing the new caption (with new
[quoted text clipped - 137 lines]
>>>>>>>> Many thanks in advance.
>>>>>>>> DeanH
DeanH - 31 Mar 2008 09:15 GMT
Many thanks Graham, especially for the perseverance ;-)

This works well. I have trimmed the code down for to fit my needs, Took out
the individual Fields updates, this stops the 250+ actions for a small 50
page document.
Took out the TOA, as I never do these. Took out the Headers and Footers as
these dont need to be updated in this process.
Moved the TOC and TOF to the end of the process so to capture the
renumbering of captions.

Here is what I have now, FYI.

Sub Update1()
Dim oStory As Range
Dim oTOC As TableOfContents
Dim oTOF As TableOfFigures
 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
For Each oTOC In ActiveDocument.TablesOfContents
       oTOC.Update
   Next oTOC
For Each oTOF In ActiveDocument.TablesOfFigures
       oTOF.Update
   Next oTOF
End Sub

Thanks again
DeanH
Graham Mayor - 31 Mar 2008 10:53 GMT
I knew we'd get there in the end ;)

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Many thanks Graham, especially for the perseverance ;-)
>
[quoted text clipped - 31 lines]
> Thanks again
> DeanH
 
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



©2010 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.