View Single Post
 
Old 10-23-2021, 03:04 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,160
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

I thought with my earlier testing the code worked on both instances (which at that time were Sequence Table fields) but now I've retested it I can see it only caught the inline field. Now it appears that the first field is in a Shape object so the code would change to ...
Code:
Sub AppendixParensIntegrated2()
'   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
    Dim oStory As Range, oFld As Field, iCount As Integer, aRng As Range, aShape As Shape
    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
      For Each aShape In ActiveDocument.Shapes
        If aShape.TextFrame.HasText Then
          For Each oFld In aShape.TextFrame.TextRange.Fields
            If oFld.Type = wdFieldSequence Then
              If oFld.Code Like "*Appendix*" Then
                oFld.Code.Text = "SEQ Appendix \# ""(#)"" "
                iCount = iCount + 1
              End If
            End If
            oFld.Update
          Next oFld
        End If
      Next aShape
      
      ActiveDocument.Fields.Update
    Set oFld = Nothing
    Set oStory = Nothing
    On Error GoTo 0
    MsgBox iCount & " instances bracketed.", vbOKOnly, "Macro complete"
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote