View Single Post
 
Old 03-03-2015, 06:48 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It is not clear what your original macro is about with respect to calls to an unidentified macro, an added document and a named document, but the following will look in each text string marked <AFF>...</AFF>, and replace UK or U.K with "United Kingdom" and add a comment to that effect. UK or U.K not tagged with <AFF>...</AFF> are ignored.

Code:
Option Explicit
Sub ChangeUK()
Dim vFindText As Variant
Dim sReplaceText As String
Dim oRng As Range
Dim oSearch As Range
Dim oFound As Range
Dim i As Long
Dim sAsk As String
    vFindText = Array("UK", "U.K.")
    sReplaceText = "United Kingdom"
    Set oRng = ActiveDocument.Range
    With oRng.Find
        Do While .Execute(FindText:="\<AFF\>*\<\/AFF\>", MatchWildcards:=True)
            Set oSearch = oRng
            For i = 0 To UBound(vFindText)
                Set oFound = oSearch
                With oFound.Find
                    .ClearFormatting
                    .Replacement.ClearFormatting
                    Do While .Execute(FindText:=vFindText(i), _
                                      MatchWholeWord:=True, _
                                      MatchWildcards:=True, _
                                      Forward:=True, _
                                      Wrap:=wdFindStop) = True
                        oFound.Text = sReplaceText
                        oFound.Comments.Add oFound, "Country name changed. Please check"
                        oFound.Collapse wdCollapseEnd
                        If oFound.End >= oSearch.End Then Exit Do
                    Loop
                End With
            Next i
        Loop
    End With
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote