View Single Post
 
Old 02-01-2024, 07:22 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 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

Here is a quick and dirty method to add the TC fields. It is somewhat flawed in using Selection objects because I can't immediately see why range won't work and couldn't be bothered figuring it out. You will have problems if there are instances of MyStyle spanning multiple paragraphs.
Code:
Sub aaa()
  Dim aFN As Footnote, aRng As Range, aRngRef As Range, sCode As String, aFld As Field
  Set aRng = Selection.Range.Sections(1).Range
  With aRng.Find
    .ClearFormatting
    .Text = ""
    .Style = "MyStyle"
    Do While .Execute
      sCode = "TC """ & aRng.Text & """ \l 1 "
      aRng.Collapse wdCollapseEnd
      Set aFld = ActiveDocument.Fields.Add(Range:=aRng, Text:=sCode)
      aFld.Select
      Selection.Font.Reset
      aRng.Start = Selection.Range.End
      aRng.End = aRng.Sections(1).Range.End
    Loop
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote