M
MAB
When I try to run a Word macro named UpdateTOC, I receive a "Run time error
'5678': Word cannot find the requested bookmark." message.
When I click the "debug" button, I'm taken to this line within the code:
"Selection.GoTo What:=wdGoToBookmark, Name:="toc""
This is the rest of the code:
```````````````````
Sub UpdateTOC()
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToBookmark, Name:="toc"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range,
RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=4, IncludePageNumbers:=True, AddedStyles:=""
.TablesOfContents(1).TabLeader = wdTabLeaderDots
End With
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToBookmark, Name:="tocend"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
End Sub
`````````````
Can anyone provide any insight in two what is going on or attempting to
happen? I have no experience in VB coding, so laymans terms may be necessary
to explain it. ;-)
Thanks.
'5678': Word cannot find the requested bookmark." message.
When I click the "debug" button, I'm taken to this line within the code:
"Selection.GoTo What:=wdGoToBookmark, Name:="toc""
This is the rest of the code:
```````````````````
Sub UpdateTOC()
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToBookmark, Name:="toc"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range,
RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=4, IncludePageNumbers:=True, AddedStyles:=""
.TablesOfContents(1).TabLeader = wdTabLeaderDots
End With
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToBookmark, Name:="tocend"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
End Sub
`````````````
Can anyone provide any insight in two what is going on or attempting to
happen? I have no experience in VB coding, so laymans terms may be necessary
to explain it. ;-)
Thanks.