View Single Post
 
Old 11-29-2024, 09:05 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Hi, Shelley Lou! The following code will do the job if there's only one array item in each paragraph. If there's more than one array item (i.e. not instances of the same item but different items) in a para, the first instance of each item will be worked on. To avoid this, the array item with the least Start number should be selected, which will require comparing all found items. This will complicate the code. One tip: I'd use array items as long as possible to avoid false hits, eg "means" may be found in different collocations.
Code:
Sub InsertTab_Before_FirstInstance()
Dim oRng As range
Dim oPar As Paragraph
Dim arrWords
Dim i As Long
    Set oRng = ActiveDocument.range
    arrWords = Array("means", "includes (without", "any part")
    For Each oPar In oRng.Paragraphs
        For i = 0 To UBound(arrWords)
            With oPar.range.Find
                .ClearFormatting
                .Replacement.ClearFormatting
                .text = arrWords(i)
                .MatchWholeWord = True
                .Replacement.text = ChrW(9) & arrWords(i)
                .Execute Replace:=wdReplaceOne
            End With
        Next i
    Next oPar
End Sub
Reply With Quote