Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-16-2023, 05:02 PM
Guessed's Avatar
Guessed Guessed is online now Get paragraph number from multlilevel list style for use in TC field Windows 10 Get paragraph number from multlilevel list style for use in TC field Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

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
If you absolutely can't build the TOC with styles, perhaps a better approach would be to build the TC field with nested Ref fields so that the TOC entries dynamically update with the current paragraph number and text.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get paragraph number from multlilevel list style for use in TC field Count number of periods and convert paragraph to a heading style jeffreybrown Word VBA 7 10-19-2019 01:15 PM
Get paragraph number from multlilevel list style for use in TC field How do I create a field that will return the current paragraph number minus one in an automatic list gugootz Word 1 11-23-2015 04:58 PM
Get paragraph number from multlilevel list style for use in TC field List Style Numbering picks up out of order number from LATER list spthomas Word 12 12-16-2013 05:23 PM
Get paragraph number from multlilevel list style for use in TC field Trouble on Using List number style in Master Document 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:29 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