Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #13  
Old 11-26-2024, 02:11 AM
Guessed's Avatar
Guessed Guessed is offline Delete a Line in a TOC Windows 10 Delete a Line in a TOC Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,187
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The first paragraph is particularly hard to delete and I guess this is because the field code is held within it. To keep things simple, I would first create a style in the document that has your 'hidden' attributes. I would actually use the font hidden property but making it white and tiny is similar in result and doesn't matter if the user has their options set to view hidden text.

There is no need to step backwards through the TOCs - just the paragraphs within the TOCs.

Then this code could be as simple as...
Code:
Sub TOC_Fiddler()
  Dim aTOC As TableOfContents, i As Integer, aRng As Range
  'Assumes you have a style called 'TOC Hidden' to apply to lines you want to hide
  For Each aTOC In ActiveDocument.TablesOfContents
    aTOC.Update
    With aTOC.Range
      For i = .Paragraphs.Count - 1 To 1 Step -1
        If .Paragraphs(i).Style = "TOC 1" And .Paragraphs(i).Next.Style = "TOC 1" Then
          .Paragraphs(i).Style = "TOC Hidden"
        End If
      Next i
    End With
  Next
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



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 12:58 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