I am trying to automate a process in SAP GUI.
I recorded a series of procedures and pasted the code in a macro sheet. I make Excel read the VBA code with the following commands:
Dim SapGuiAuto As Object
Dim Application As Object
Dim Connection As Object
Dim Session As Object
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
Set Connection = Application.Children(0)
Set Session = Connection.Children(0)
For one of the parts SAP makes a lot of calculations which takes a few minutes and around the middle of it, Excel generates the message:

I have to click OK to continue, then it pops-up non-stop and I have to do it like 10-15 times, which removes the point of automation.
When doing it without a macro, SAP does not give me any error.
I tried turning it off with
Application.DisplayAlerts = False
It instead gives me:

I searched the net and the site, but there was barely any useful info maybe because my question is too specific.
Some additional info:

My Excel version is 2013.
How can I achieve one of the three solutions I can think of:
Application.Wait, but without successStorax above actually gave a link to another topic with the solution of the question.
Code here:
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
If you use 64-bit Microsoft Office you should slightly change the code offered by M_Delineshev according to the Declare Statement. Try to use this version:
Private Declare PtrSafe Function _
    CoRegisterMessageFilter Lib "OLE32.DLL" _
    (ByVal lFilterIn As Long, _
    ByRef lPreviousFilter) As LongPtr
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With