none
Getting a Word Not Respnding Message in the Middle of a Macro Run RRS feed

  • Question

  • I have written a Word Macro that takes a fair amount of time to run.  At one point during the run, in the top line of the Word <g class="gr_ gr_17 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" data-gr-id="17" id="17">Window</g> I get a message: "Word is Not Responding".  However, if I do nothing, in a few minutes the message disappears and the Macro keeps running and then finishes.

    So far as I can tell everything has worked correctly in the Macro.

    What could be causing the Not Responding Message?

    What makes it disappear?

    Is it something I should worry about?


    Lewis D. Eigen




    • Edited by LDEigen Saturday, May 5, 2018 7:49 PM
    Saturday, May 5, 2018 7:46 PM

Answers

  • Word's UI thread must retrieve and dispatch Windows' messages from it's message queue.  This is referred to as "pumping messages".  When an application stops pumping messages on it's UI thread for a time because it is doing other work (e.g., doing complex calculations or doing slow file i/o, or running certain macros) Windows gives the "Application is Not Responding" message.  When the UI thread starts pumping messages again (calculations finished, i/o is complete, or message pumping is able to be resumed) then the not responding message goes away.  You could see the same thing happen if any long-running operation was performed on the UI thread such that message pumping was paused for a time.  I forget the exact number of seconds that Window's will wait for message pumping to resume before it issues the warning.  Some use DoEvents to allow message processing to occur during macro execution and others find different ways to deal with the issue.

    • Edited by RLWA32 Sunday, May 6, 2018 1:23 AM
    • Marked as answer by LDEigen Sunday, May 6, 2018 6:03 AM
    Sunday, May 6, 2018 1:22 AM
  • You need to give Word some breathing space for its own housekeeping. This can be done by inserting:
    DoEvents
    at the appropriate point(s) in the code. If you're running a long loop, you might use a counter to trigger DoEvents every so often, for example:

    Dim i As Long
    With ActiveDocument
      For i = 1 To .Paragraphs.Count
        'do para processing, then
        If i Mod 100 = 0 Then DoEvents
      Next
    End With

    You should also: (a) avoid using selections wherever possible; and (b) turn off screen updating, unless you need to interact with selections as the macro runs.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by LDEigen Monday, May 7, 2018 12:25 AM
    Sunday, May 6, 2018 10:54 PM

All replies

  • Word's UI thread must retrieve and dispatch Windows' messages from it's message queue.  This is referred to as "pumping messages".  When an application stops pumping messages on it's UI thread for a time because it is doing other work (e.g., doing complex calculations or doing slow file i/o, or running certain macros) Windows gives the "Application is Not Responding" message.  When the UI thread starts pumping messages again (calculations finished, i/o is complete, or message pumping is able to be resumed) then the not responding message goes away.  You could see the same thing happen if any long-running operation was performed on the UI thread such that message pumping was paused for a time.  I forget the exact number of seconds that Window's will wait for message pumping to resume before it issues the warning.  Some use DoEvents to allow message processing to occur during macro execution and others find different ways to deal with the issue.

    • Edited by RLWA32 Sunday, May 6, 2018 1:23 AM
    • Marked as answer by LDEigen Sunday, May 6, 2018 6:03 AM
    Sunday, May 6, 2018 1:22 AM
  • This is a great explanation of a complex issue.  Thanks.  Now I know that I need not worry about it, but thanks to you, I understand a lot more about how Word works.

    Lewis D. Eigen

    Sunday, May 6, 2018 6:06 AM
  • You need to give Word some breathing space for its own housekeeping. This can be done by inserting:
    DoEvents
    at the appropriate point(s) in the code. If you're running a long loop, you might use a counter to trigger DoEvents every so often, for example:

    Dim i As Long
    With ActiveDocument
      For i = 1 To .Paragraphs.Count
        'do para processing, then
        If i Mod 100 = 0 Then DoEvents
      Next
    End With

    You should also: (a) avoid using selections wherever possible; and (b) turn off screen updating, unless you need to interact with selections as the macro runs.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by LDEigen Monday, May 7, 2018 12:25 AM
    Sunday, May 6, 2018 10:54 PM
  • Paul, you are turning me into a decent VBA Programmer.  I can use this technique in several places.  Thanks so much.  Your help is invaluable.

    Lewis D. Eigen

    Monday, May 7, 2018 12:27 AM