Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old Yesterday, 12:48 PM
Charles Kenyon Charles Kenyon is offline Delete a table of contents Windows 11 Delete a table of contents Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,601
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete a table of contents Word Table of Contents - when I title a heading "table", table of contents shows "table2" jncuk Word 8 04-15-2020 07:01 PM
Delete a table of contents Manipulating Headings so Image contents is correctly referenced in Table of Contents dynamictiger Word 2 05-29-2019 05:41 AM
Delete a table of contents Table of Contents -"Permanently" Setting Table of Contents Option KRoger Word 3 03-01-2019 06:36 AM
Delete a table of contents 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft