View Single Post
 
Old 04-09-2020, 12:41 PM
Seti Seti is offline Windows 10 Office 2019
Novice
 
Join Date: Apr 2020
Posts: 2
Seti is on a distinguished road
Default

Hi,


It can be repeated forever if you move to the end of the line after making the edit, I think. The code below works for me, anyways:


Code:
Sub Invited()


    'Go to the beginning of the document
    Selection.HomeKey Unit:=wdStory
    
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "invited"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = True
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        
    End With

    While Selection.Find.Execute
    
        Selection.HomeKey Unit:=wdLine
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        
        Dim strW As String
        strW = ChrW(55357) & ChrW(56395)
        Selection.TypeText Text:=strW
    

        'Without line this it runs forever

        Selection.EndKey Unit:=wdLine
        
    Wend
    
End Sub
I'm guessing the reason it kept going forever before was that the Selection kept on jumping to the start of the line, before the previous thing it found, and then went on to find the previous thing it found, again, and so on!
Reply With Quote