![]() |
|
#6
|
|||
|
|||
|
Charles,
Well, you are right. That code did nothing with your example. I think part of the problem will be dealing with TOCs that are in a container as well as those that are not and not with a preceding TOC Heading paragraph. Both of these seem to work with your examples: Code:
Sub DeleteTOCs_and_Containers()
Dim oRng As Range
Dim TOC As TableOfContents
Dim lngIndex As Long
For lngIndex = ActiveDocument.TablesOfContents.Count To 1 Step -1
Set TOC = ActiveDocument.TablesOfContents(lngIndex)
TOC.Range.Fields(1).Locked = False
Set oRng = TOC.Range.Fields(1).result
oRng.MoveStart Unit:=wdParagraph, Count:=-2
oRng.MoveEnd Unit:=wdCharacter, Count:=1
Select Case True
Case oRng.Paragraphs(1).Style = "TOC Heading"
Case Else
oRng.MoveStart wdParagraph, 1
End Select
oRng.Delete
Next lngIndex
lbl_Exit:
Exit Sub
End Sub
Sub DeleteTOCs_and_ContainersII()
Dim TOC As TableOfContents
Dim oRng As Range
Dim lngIndex As Long
For Each TOC In ActiveDocument.TablesOfContents
Set oRng = TOC.Range.Paragraphs.First.Previous.Range
Application.CommandBars.ExecuteMso ("TableOfContentsRemove")
On Error GoTo Skip
If oRng.Style = "TOC Heading" Then
oRng.Delete
End If
Skip:
Next TOC
lbl_Exit:
Exit Sub
End Sub
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Word Table of Contents - when I title a heading "table", table of contents shows "table2"
|
jncuk | Word | 8 | 04-15-2020 07:01 PM |
Manipulating Headings so Image contents is correctly referenced in Table of Contents
|
dynamictiger | Word | 2 | 05-29-2019 05:41 AM |
Table of Contents -"Permanently" Setting Table of Contents Option
|
KRoger | Word | 3 | 03-01-2019 06:36 AM |
Code to find a named (bookmarked?) table, replicate a row or table, and delete a specified table.
|
kevinbradley57 | Word VBA | 9 | 09-21-2017 04:58 PM |
| Text inside text boxes create headings inside my table of contents!!! How do I delete the created he | carstj | Word | 3 | 04-11-2016 12:46 PM |