Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-25-2024, 09:57 PM
KoolBreeze KoolBreeze is offline Delete a Line in a TOC Windows 11 Delete a Line in a TOC Office 2021
Novice
Delete a Line in a TOC
 
Join Date: Nov 2024
Posts: 8
KoolBreeze is on a distinguished road
Default

The modified version of Guessed's code below works as intended. Instead of trying to delete the top entry in the TOC, I changed the formatting to make it invisible. There may be a better way of doing it, but this seems to work very well.




Thanks guys for all of the help!



Code:
Sub TOC_Fiddler()
  Dim aPar As Paragraph, aTOC As TableOfContents, i As Integer, aRng As Range, lngNumTOC As Long
  
  lngNumTOC = ActiveDocument.TablesOfContents.Count
  For Each TOC In ActiveDocument.TablesOfContents
    
    Set aTOC = ActiveDocument.TablesOfContents(lngNumTOC)
    aTOC.Update
    
    Set aRng = aTOC.Range
    For i = aRng.Paragraphs.Count - 1 To 1 Step -1
         If aRng.Paragraphs(i).Style = "TOC 1" And aRng.Paragraphs(i).Next.Style = "TOC 1" Then
            If i > 1 Then
                aRng.Paragraphs(i).Range.Delete
            Else
                aRng.Paragraphs(i).SpaceAfter = 0
                aRng.Paragraphs(i).SpaceBefore = 0
                aRng.Paragraphs(i).Range.Font.Size = 1
                aRng.Paragraphs(i).Range.Font.ColorIndex = wdWhite
            End If
        End If
    Next i
    
    lngNumTOC = lngNumTOC - 1
  Next

End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete a Line in a TOC Horizontal line I can't delete goingvirtual Word 2 09-09-2018 02:58 AM
Delete a Line in a TOC Delete certain characters from a line Helend269 Word VBA 5 01-09-2018 12:08 PM
Delete a Line in a TOC Delete line above sidenote JackDaniels Word 2 10-01-2016 08:04 AM
If Statement in vba to Delete a Line mbesspiata Excel Programming 4 04-08-2014 04:32 AM
Cannot delete line adkr Office 1 04-07-2010 09:26 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:16 PM.


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