none
Microsoft Word 2013 crashes on running a VBA code / plugin RRS feed

  • Question

  • Word 2013 crashes when running a VBA / macro on the documents that have comments section enabled. The functionality of the macro is to search 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 / if no mark up is selected, word doesn't crash even though we perform search and replace in the main text / document as well.

    Word crashes @ Selection.Find.Execute Api. (OS : Win 10), not always but a quite often

    Installed latest updates of word 2013, but still crashes; Tried common solutions for the crash ((such as Disabling word Add-ins, Disable hardware acceleration) of MS Word crash problems, but they didn’t work

    VBA macro  (posting the required ones, not the full code)

    With Selection.Find

            .Text = "&"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With

    ' Now, let's pull up the comments pane and look for slashes in there
            ActiveWindow.View.SplitSpecial = wdPaneComments

    ' Go to the top of the document
        Selection.HomeKey unit:=wdStory

        If Selection.Find.Execute = True Then 'Word crashes here..
                  Selection.TypeBackspace

    Let me know if you have any pointers on this issue.

    please note that the same macro code works well in Word 2007 (OS : Win 7) and before for years.


    Friday, April 15, 2016 1:58 PM

Answers

  • Hi lingabalaji,

    >> Changing the above search logic doesn't crash the word.

    Which code you used will not crash word? To be honesty, I am not able to reproduce your issue at my side. Based on your code, it seems you want to remove all the “&”, I suggest  you try the code below:

    Sub ReplaceComments()
        Dim c As Word.Comment
        Dim cs As Word.Comments
        Set cs = ActiveDocument.Comments
    
        For Each c In cs
        c.Range.Select
          With Selection.Find
             .Text = "&"
             .Replacement.Text = ""
             .Forward = True
             .Wrap = wdFindStop
             .Format = False
             .MatchCase = False
             .MatchWholeWord = False
             .MatchWildcards = False
             .MatchSoundsLike = False
             .MatchAllWordForms = False
           End With
           If Selection.Find.Execute = True Then
             Selection.TypeBackspace
           End If
        Next c
     End Sub

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, April 21, 2016 5:58 AM

All replies

  • Hi lingabalaji,

    I made a test with steps below, but I failed to reproduce your issue.

    1. Create a document, write contents, and add comments
    2. Test with your code, and it run correctly.

    >> Word crashes @ Selection.Find.Execute Api. (OS : Win 10), not always but a quite often

    Could you identify how this issue happened? First, I suggest you achieve your requirements by finding “&” manually to check whether this issue still exist. Second, I suggest you create a simple document, and check whether it is related with this special document.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, April 18, 2016 2:46 AM
  • First, I suggest you achieve your requirements by finding “&” manually to check whether this issue still exist. 

    << Manually it works.

    Second, I suggest you create a simple document, and check whether it is related with this special document.

    <<Created a simple new document with comments and created a new macro, the word crashes still. Word crashing is sporadic but can reproduce the crash.

    Monday, April 18, 2016 3:00 PM
  • Hi lingabalaji,

    Could you share us your test simple document and details step? Then we could test at our side.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, April 19, 2016 3:26 AM
  • 1. Create a simple document with one text and add comment.

    2. Insert the sample comment text as below:

    A: &
    B: &
    C: &
    D: &
    E: &
    F: &
    G: &
    H: &
    I: &
    J: &
    K: &
    L: &
    M: &
    N: &
    O: &
    P: &

    3.  Create one Test macro as below:

    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; Out of 10 times, word crashes here twice or thrice. (update the comment text accordingly, when all '&'s are cleared). 

    Let me know if you are able to reproduce the issue.

    OS: Win 10; Word 2013.


    Tuesday, April 19, 2016 1:51 PM
  • Does this occur on one computer only? Did you try the code on several?

    Best regards, George

    Tuesday, April 19, 2016 2:29 PM
  • yes. it happens in different machines.


    Tuesday, April 19, 2016 3:33 PM
  • What external add-ins do you have?


    Best regards, George

    Tuesday, April 19, 2016 3:38 PM
  • I can check and update here ( if you need the list ), but I tried disabling the app add-ins, it didn't help.

    This Macro is part of project specific Add in, which is written in .dot file. 

    Tuesday, April 19, 2016 3:46 PM
  • Hi lingabalaji,

    I failed to reproduce your issue with your steps. Have you installed KB 3114989? If you have, I suggest you uninstall it and test again. If not, I suggest you repair or reinstall your Office to try again.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, April 20, 2016 6:14 AM
  • (KB 3114989 is not installed) we did fresh installation, after which the issue continued and tried with repair - they didn't help!

    Changing the above search logic doesn't crash the word.

    Came across this link

    http://answers.microsoft.com/en-us/office/forum/office_2010-customize/word-vba-that-worked-in-2007-crashes-in-2010/3de9f437-7770-47e0-b4d5-3ad7055b2352?page=1&auth=1 

    which talks about a similar issue, but no solution is provided. 

    Could you let me know any other solution that we could try out?

    Wednesday, April 20, 2016 2:30 PM
  • Hi lingabalaji,

    >> Changing the above search logic doesn't crash the word.

    Which code you used will not crash word? To be honesty, I am not able to reproduce your issue at my side. Based on your code, it seems you want to remove all the “&”, I suggest  you try the code below:

    Sub ReplaceComments()
        Dim c As Word.Comment
        Dim cs As Word.Comments
        Set cs = ActiveDocument.Comments
    
        For Each c In cs
        c.Range.Select
          With Selection.Find
             .Text = "&"
             .Replacement.Text = ""
             .Forward = True
             .Wrap = wdFindStop
             .Format = False
             .MatchCase = False
             .MatchWholeWord = False
             .MatchWildcards = False
             .MatchSoundsLike = False
             .MatchAllWordForms = False
           End With
           If Selection.Find.Execute = True Then
             Selection.TypeBackspace
           End If
        Next c
     End Sub

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, April 21, 2016 5:58 AM