Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-07-2015, 02:15 AM
gmayor's Avatar
gmayor gmayor is offline Update fields and Tables of Content with one macro Windows 7 64bit Update fields and Tables of Content with one macro Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will unprotect a form, and update all the fields, including tables of contents
Code:
Sub UpdateAllFields()
Dim oStory As Range
Dim oTOC As TableOfContents
Dim bProtected As Boolean
    If ActiveDocument.ProtectionType <> wdNoProtection Then
        bProtected = True
        ActiveDocument.Unprotect Password:=""
    End If
    For Each oTOC In ActiveDocument.TablesOfContents
        oTOC.Update
    Next oTOC
    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
    If bProtected = True Then
        ActiveDocument.Protect _
                Type:=wdAllowOnlyFormFields, _
                NoReset:=True, _
                Password:=""
    End If
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Forms fields: edit content easily in tables kirby gilman Word 8 12-04-2014 08:43 AM
Update fields and Tables of Content with one macro Macro to select and update all tables in document CircleG Word VBA 6 10-17-2014 07:25 PM
Auto Update Fields Macro kveldulv Outlook 0 06-07-2013 02:30 PM
Update fields and Tables of Content with one macro 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:43 AM.


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