View Single Post
 
Old 10-21-2021, 05:39 PM
Charles Kenyon Charles Kenyon is offline Windows 10 Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,529
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

Quote:
Originally Posted by laith93 View Post
Thank you MR. Charles
Again the above macros work to find and replace normal text anywhere, but do not look for the text of field codes ex: {Seq Appendix \* Arabic}.
Here the sample file you can try to explore what I mean.
That page shows how to loop through stories in a document to get to all parts.


Code:
Sub AppendixParens()
'   Charles Kenyon 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
    On Error Resume Next
    For Each oStory In ActiveDocument.StoryRanges
        Do
            For Each oFld In oStory.Fields
                If oFld.Type = wdFieldSequence Then
                    If InStr(1, oFld.Code, "Appendix") > 0 Then
                        oFld.Result.InsertAfter ")"
                        oFld.Result.InsertBefore "("
                    End If
                End If
            Next oFld
        Loop Until oStory Is Nothing
     Next
    Set oFld = Nothing
    Set oStory = Nothing
    On Error GoTo -1
 End Sub
Reply With Quote