1
votes

Word 2013 crashes when running a VBA/macro on a document that has comments section enabled. The macro searches for a character and replaces it with "" (blank) in the comments section and main document. This is done using Selection.Find.Execute API. When there is no comments section or no mark up is selected, Word doesn't crash.

This is on Windows 10 and word 2013. The macro works well in Word 2007 and Windows 7.

Reproducible steps:

  1. Create a simple document with one text and add comment.

  2. Insert the sample comment text as below: (add vertically like: A : & (enter) and so on)

    A: & B: & C: & D: & E: & F: & G: & H: & I: & J: & K: & L: & M: & N: &
    
  3. Create macro:

    Sub Test_Macro()
        ActiveWindow.View.SplitSpecial = wdPaneComments
        With Selection.Find
                .Text = "&"
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindStop
                .Format = False
                .MatchCase = False
                .MatchWholeWord = False
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
        End With
    
        Selection.HomeKey unit:=wdStory
    
        If Selection.Find.Execute = True Then
           'We found the slash.  Delete it.
            Selection.TypeBackspace
        End If
    
    End Sub
    
  4. Execute the Macro (& will be cleared). Keep on executing again; Word will crash 2-3 times out of 10. (update the comment text accordingly, when all &s are cleared).

1
Exactly what is the error message you're getting, and can we see the faulty line of code and a bit of surrounding context?Mathieu Guindon
word crashes. There's no error message as such. when we look at eventviewer, the stacktrace shows at wwlib.dll. Here is the faulty line of code: ' Go to the top of the document Selection.HomeKey unit:=wdStory If Selection.Find.Execute = True Then 'Word crashes here.. Selection.TypeBackspaceBalaji
word crashes at selection.find.execute; when i change the logic with some custom logic, word 2013 doesn't crash. need to know if any micorosoft update has to be installed or is it a bug?Balaji
The most likely cause being the some custom logic part, it's very hard to tell (read: impossible) without knowing more about exactly what you're trying to accomplish that Word doesn't like.Mathieu Guindon
If you don't include steps to reproduce the problem (including code) it's impossible for anyone to help you. Please read the guidelines on asking questions on this site in the help center.Cindy Meister

1 Answers

0
votes

I do not see a question in your text, so I can not answer, but I can confirm that Microsoft Word 2013 crashes on ActiveDocument.Content.Find.Execute. I routinely had to work around this by manually exercising the Replace dialog before executing the macro. This worked (almost) every time. Now I found this post that says that it has something to do with Execute running with an empty undo record. I was able to work around this issue by inserting a line of code that adds some text to the last paragraph of the document right after the undo record is created.