Word bug in Find & Replace

Mikie Bee 20 Reputation points
2025-06-07T23:45:00.59+00:00

I've done further isolation in my code and narrowed it down to what I think is a bug in Word. I'm on Word Version 2505 (Build 18827.20140) which is suppose to be the latest. I reinstalled Office this morning to make sure I'm really up to date.. This problem is easy to reproduce outside my code. I created a word document and put several repeating paragraphs. At the end of each paragraph if placed blahblahblah (you can use anything). Then did a ctl H (find & replace) Find blahblahblah replacement testtext and it worked flawlessly. However when I attempt to do what my code is doing Find blahblahblah replace ^m (page break) it appear to have worked. However when you close the find window, scroll up and down, and try to select a page, Word hangs and you have to kill it from the task manager. My code is basically doing mail merge on steroids and creates the lettters as on big text field, places the results in a word document, and then replaces blahblahblah with ^m and saving it as pdf or word. I also hangs when it tries the find and replace. My code has been working fine for the last five years without a problem. It only started having this problem since 5/15 (last time I ran it successfully without the lock up). I hope you can address this quickly as I am dead in the water with my automation since I'm using vba in excel and word to create the final form of the required output file. Thank you! I've attached a sample word document I used with the find and replace and also additional info about my laptop.

System Info

Update History

Find-Replace Options Selected

Office Version

Test Sample Text

Word Management
Word Management
Word: A family of Microsoft word processing software products for creating web, email, and print documents.Management: The act or process of organizing, handling, directing or controlling something.
1,030 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jay Freedman 201 Reputation points
    2025-06-08T00:45:11.72+00:00

    Using nearly the same updated version (Ver. 2505, Build 18827.20128), I see the same behavior with the Replace dialog and the ^m code. Word locked up, and after killing and restarting it, a "repaired" copy of the document appeared -- the target word was removed, but there were no page breaks.

    Although Microsoft may eventually get around to fixing the bug, I suggest permanently using a different method. Use some version of the following code instead of the .Find.Execute with ^m.

    Sub DoReplacement()
        Dim strTarget As String
        Dim rg As Range
    
        
    strTarget = "BlahBlahBlahBlah"  
    Set rg = ActiveDocument.Range  
    
      
    On Error GoTo ErrHdl  
    
      
    With rg.Find  
        .Text = strTarget  
        .MatchCase = True  
        .MatchWholeWord = True  
        While .Execute  
            rg.Text = ""  
            rg.InsertBreak wdPageBreak  
            rg.Collapse wdCollapseEnd  
            DoEvents  
        Wend  
    End With  
    
      
    Exit Sub  
    
    ErrHdl:
        MsgBox Err.Number & vbCr & Err.Description
    End Sub
    
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.