I'm sure that Paul or others could improve on this. You would include the password for modification in the UpdateCaptions routine. In this code, it is set as "xyz."
Code:
Sub protectDocNoMods(Str_password As String)
'
'
ActiveDocument.Protect Password:=Str_password, _
NoReset:=False, Type:= _
wdAllowOnlyReading, _
UseIRM:=False, EnforceStyleLock:=False
End Sub
Sub UnprotectDocNoMods(Str_password As String)
'
ActiveDocument.Unprotect (Str_password)
End Sub
Sub UpdateCaptions()
Dim Str_password As String
Str_password = "xyz"
Call UnprotectDocNoMods(Str_password)
' From Greg Maxey 2013-09-30
' http://answers.microsoft.com/en-us/office/forum/office_2007-word/how-to-update-all-fields-in-a-document-at-once/54b43181-0ea7-4abc-bfb9-e0555125dfe5?page=3
'
Dim rngStory As Word.Range, lngJunk As Long, oShp As Shape
Dim oToc As TableOfContents, oTof As TableOfFigures, oToa As TableOfAuthorities
'
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
For Each oTof In ActiveDocument.TablesOfFigures ' Added by CKK
oTof.Update
Next oTof
' For Each oToa In ActiveDocument.TablesOfAuthorities ' Added by CKK
' oToa.Update
' Next oToa
Next
'
Call protectDocNoMods(Str_password)
'
End Sub
This was cobbled together from other code I have on hand. I have not tested the above because I am supposed to be asleep right now. See also
Installing Macros which has some excellent code for updating all fields in a document that could be incorporated instead.