View Single Post
 
Old 10-22-2021, 04:42 AM
Charles Kenyon Charles Kenyon is offline Windows 10 Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,530
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Andrew, I ran your macro on the sample file provided and it did nothing because of the term "Table." When I changed it to "Appendix" it caught the in-line instance but not the one in the Textbox.


Code:
Sub AppendixParensIntegrated()
'   Charles Kenyon and Andrew Lockton using code from Graham Mayor
'   October 21, 2021
'   https://www.msofficeforums.com/word/47835-putting-parentheses-around-sequence-number-caption-label.html
'   Instead of adding () characters, change the field's display format to include them
    Dim oStory As range, oFld As Field, iCount As Integer, aRng As range
    On Error Resume Next
      For Each oStory In ActiveDocument.StoryRanges
        For Each oFld In oStory.Fields
          If oFld.Type = wdFieldSequence Then
            If oFld.Code Like "*Appendix*" Then
              oFld.Code.Text = "SEQ Appendix \# ""(#)"" "
              iCount = iCount + 1
            End If
          End If
        Next oFld
      Next oStory
      ActiveDocument.Fields.Update
    Set oFld = Nothing
    Set oStory = Nothing
    On Error GoTo 0
    MsgBox iCount & " instances bracketed.", vbOKOnly, "Macro complete"
End Sub
Reply With Quote