Hello,
I have a macro that should automatically update the table of contents using VBA, the only problem is that it only appears to work the first time.
I have a section of text at the beginning of a document that needs to be hidden before the doc can be printed. When you click a button to run the VBA and hide the text, the TOC is updated (should be) to make sure that everything matches up. After the document is printed, the button should be clicked again to show the text for online viewing. The TOC should be updated again, but the function only appears to update the TOC the first time. Here is what I have currently for updating the TOC:
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:=”TOC”
Selection.Find.ClearFormatting
With Selection.Find
.Text = “”
.Replacement.Text = “”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Fields.Update
I have tried many other things as well, so I won’t list them here, but if anyone has seen this happen or can help me in any way, I would greatly appreciate it!
Thanks!