![]() |
|
#5
|
|||
|
|||
|
Hi Greg,
I ran your code in a document with three TOCs, one a bare field, the other in the Content Controls. None were removed. The following was offered by John Korchock in response to my question about using SendKeys: Code:
' Source - https://stackoverflow.com/a/79851355
' Posted by John Korchok
' Retrieved 2025-12-19, License - CC BY-SA 4.0
Sub DeleteAllTOCs()
Dim f As Field, TOCRange As Range
Application.ScreenUpdating = False
Application.StatusBar = "We are deleting tables of content... Be patient..."
For Each f In ActiveDocument.Fields
If f.Type = wdFieldTOC Then
f.Locked = False
f.Select
Set TOCRange = Selection.Range
With TOCRange
.MoveStart Unit:=wdParagraph, Count:=-1
.MoveEnd Unit:=wdParagraph, Count:=1
.Delete
End With
Set TOCRange = Nothing
End If
Next f
Application.ScreenUpdating = True
Application.StatusBar = ""
Application.ScreenRefresh
MsgBox "Done."
End Sub
That code does work on my sample. I am still hoping to find an answer about using SendKeys to mimic the Ribbon Accelerator buttons. |
|
|
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 |