![]() |
|
#1
|
||||
|
||||
![]()
A string is not the same thing as a Range and a paragraph range includes a return at the end of it
I'm not a fan of TC fields and you haven't explained why you aren't building the TOC using a style which avoids the need to place a TC field at all. The static TC field means that it will become out of step with the paragraph text or number if either were to change later. Code:
Sub StaticTC() Dim myRange As Range, thisPara As String, currentNumber As String Dim spaceChar As String, tcText As String spaceChar = " " Set myRange = Selection.Paragraphs(1).Range myRange.End = myRange.End - 1 thisPara = myRange.Text ' This is the current paragraph's text currentNumber = myRange.ListFormat.ListString 'will be empty if not an autonumber tcText = Trim(currentNumber & spaceChar & thisPara) 'remove leading and trailing spaces myRange.Collapse Direction:=wdCollapseEnd ActiveDocument.TablesOfContents.MarkEntry Range:=myRange, Entry:=tcText, Level:=1 End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
jeffreybrown | Word VBA | 7 | 10-19-2019 01:15 PM |
![]() |
gugootz | Word | 1 | 11-23-2015 04:58 PM |
![]() |
spthomas | Word | 12 | 12-16-2013 05:23 PM |
![]() |
nattasiray | Word | 2 | 12-16-2011 08:01 PM |
Numbered List paragraph style prints out incorrectly when converted to PDF - Help! | kimrussell68 | Word | 0 | 02-02-2010 07:58 AM |