#1
|
|||
|
|||
How to update fields in all header definitions
I need to toggle a document between two sets of field values. I have everything working except that ActiveDocument.Fields.Update does not update fields in the page header and footer. I recorded some code to do this but it only updates the header for the section where the cursor is located. I think the object I need is something like the following, but I'm having trouble with indexes and For loops.
ActiveDocument.Sections(iSectInd).Headers(1).Range .Fields.Update Can someone help untangle this? Thank! |
#2
|
|||
|
|||
Probably the easiest way is:
Code:
Sub ScratchMacro() ActiveDocument.PrintPreview ActiveDocument.ClosePrintPreview End Sub Code:
Public Sub UpdateAllFields() Dim rngStory As Word.Range Dim lngJunk As Long Dim oShp As Shape Dim oToc As TableOfContents lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType For Each rngStory In ActiveDocument.StoryRanges 'Iterate through all linked stories Do On Error Resume Next rngStory.Fields.Update Select Case rngStory.StoryType Case 6, 7, 8, 9, 10, 11 If rngStory.ShapeRange.Count > 0 Then For Each oShp In rngStory.ShapeRange If oShp.TextFrame.HasText Then oShp.TextFrame.TextRange.Fields.Update End If Next End If Case Else 'Do Nothing End Select On Error GoTo 0 'Get next linked story (if any) Set rngStory = rngStory.NextStoryRange Loop Until rngStory Is Nothing For Each oToc In ActiveDocument.TablesOfContents oToc.Update Next oToc Next End Sub |
#3
|
|||
|
|||
Your first code does the trick. Thanks. A question: I assumed it included the equivalent of ".Fields.Update", so I removed that from my macro. But then fields in the main text didn't get updated. How does the print preview happen to update the headers?
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Auto Update Fields Macro | kveldulv | Outlook | 0 | 06-07-2013 02:30 PM |
macro to update fields | PeaceDove | Word | 3 | 01-17-2012 02:45 PM |
Macro to update fields | rhatx | Word VBA | 0 | 03-02-2011 12:14 PM |
VBA to update certain (but not all) fields | sparkyrose | Word VBA | 0 | 05-20-2010 12:50 PM |
Can no longer update fields! | slindsay | Word | 0 | 09-03-2009 05:10 PM |