Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-10-2014, 08:45 AM
ChrisBrewster ChrisBrewster is offline How to update fields in all header definitions Windows 7 64bit How to update fields in all header definitions Office 2010 64bit
Advanced Beginner
How to update fields in all header definitions
 
Join Date: Jan 2014
Posts: 36
ChrisBrewster is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 02-10-2014, 09:06 AM
gmaxey gmaxey is offline How to update fields in all header definitions Windows 7 32bit How to update fields in all header definitions Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Probably the easiest way is:

Code:
Sub ScratchMacro()
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
End Sub
or:

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 02-10-2014, 10:33 AM
ChrisBrewster ChrisBrewster is offline How to update fields in all header definitions Windows 7 64bit How to update fields in all header definitions Office 2010 64bit
Advanced Beginner
How to update fields in all header definitions
 
Join Date: Jan 2014
Posts: 36
ChrisBrewster is on a distinguished road
Default

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?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Update Fields Macro kveldulv Outlook 0 06-07-2013 02:30 PM
How to update fields in all header definitions 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft