Martin Dreher
Martin Dreher

Reputation: 1564

How to deal with "Microsoft Excel is waiting for another application to complete an OLE action"

When automating other MS-Office applications with excel, I frequently get ok-only prompts saying that Microsoft Excel is waiting for another application to complete an OLE action.

This only happens when automating lengthy tasks.

How can I deal with this in an appropriate fashion?

Two recent examples (I recon the code is less important):

notes:

As suggested on other sources, I do wrap my code into Application.DisplayAlerts = False. This, however, seems like a horrible idea, since there might actually be cases where I do need to be alerted.

Upvotes: 6

Views: 13016

Answers (2)

user1487861
user1487861

Reputation: 472

I tried the COM API code as well, which works. But it is only useful in so far as you don't see the error - the 30-sec delay every time the error is triggered still happens which makes this unworkable for me.

The better change I have made is to turn off "Real time presence in Microsoft Office" in Drive File Stream (the google product). This has (so far!) resolved the issue for me. I'm guessing there is some sort of clash between this and another excel addin.

Upvotes: 0

Darren Bartrup-Cook
Darren Bartrup-Cook

Reputation: 19847

I'll add the code that @Tehscript linked to in the comments.

You can solve this by using the COM API to remove VBA's message filter. This will prevent COM from telling VBA to displaying a message box when it thinks the process you're calling has blocked. Note that if the process really has blocked for some reason this will prevent you from receiving any notification of that. [source]

I think this is the code I used back in 2006 for the same problem (it worked).

Private Declare Function _
    CoRegisterMessageFilter Lib "OLE32.DLL" _
    (ByVal lFilterIn As Long, _
    ByRef lPreviousFilter) As Long

Sub KillMessageFilter()  
    '''Original script Rob Bovey  

    '''https://groups.google.com/forum/?hl=en#!msg/microsoft.public.excel.programming/ct8NRT-o7rs/jawi42S8Ci0J
    '''http://www.appspro.com/

    Dim lMsgFilter As Long

    ''' Remove the message filter before calling Reflections.
    CoRegisterMessageFilter 0&, lMsgFilter

    ''' Call your code here....

    ''' Restore the message filter after calling Reflections.
    CoRegisterMessageFilter lMsgFilter, lMsgFilter

End Sub

Upvotes: 10

Related Questions