View Single Post
 
Old 03-16-2023, 06:08 AM
TallTrees TallTrees is offline Windows 10 Office 2021
Novice
 
Join Date: Jul 2022
Posts: 8
TallTrees is on a distinguished road
Default Get paragraph number from multlilevel list style for use in TC field

Hi,

I am trying to insert a TC marker as part of a macro. It is inserting the TC marker correctly with the text I want but unfortunately doesn't seem to pick up the number which is applied to the current paragraph.

The parapraph that I am applying my macro to is using a style which is in a multilevel list and has number '1' set. I followed Shauna's guide for setting up the numbering and it works really well.



As an example it looks like this (with proper alignment!)

Code:
1    Some text here 
  2    Some more text
Desired output is something like this if I was to run the macro at the first paragraph:

Code:
1    Some text here { TC "1   Some Text here" \f C \l "1" }
  2    Some more text

What I actually get is (note the omission of the '1')



Code:
1    Some text here { TC "Some Text here" \f C \l "1" }
 2    Some more text

Some code with comments may help to explain a bit more:

Code:
Dim myRange As Range
myRange = Selection.Paragraphs(1).Range
Dim thisPara as String
Dim currentNumber as String
Dim spaceChar as String
Dim tcText as String
spaceChar = " "

' This is the current paragraph's text
thisPara = myRange 

' I expected to be able to get the current number using the line below. But it's always blank. It doesn't even return "nothing" like the documentation says it should. I've tried calling it directly as well (e.g Selection.Paragraphs(1).Range.ListFormat.ListString)
currentNumber = myRange.ListFormat.ListString 

' Some concatenation...
tcText = currentNumber & spaceChar & thisPara

 ActiveDocument.TableOfContents.MarkEntry Range:=myRange, Entry:=tcText, Level:=1
It seems that the Range.ListFormat.ListString is empty. Before trying to use this I was attempting to just select the current paragraph, hoping it'd also grab the number, but it just finds the text of the paragraph.


Does anyone know what I am doing wrong? Happy to provide more information if needed but I think there is enough information in my post.

Thanks
Reply With Quote