3

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:
enter image description here

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:

enter image description here

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

Some additional info:

  1. My laptop is from work and I cannot install any additional software or updates to it without permission.
  2. I tried checking the Excel option for DDE, but it only gives me an error when I try to run the script.
    enter image description here

My Excel version is 2013.

How can I achieve one of the three solutions I can think of:

  1. Disable the pop up for OLE
  2. Make it automatically click OK every time it appears
  3. Make Excel freeze and wait while SAP does its thing? (Don't know if that makes sense.) Tried with Application.Wait, but without success
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
M_Delineshev
  • 115
  • 1
  • 3
  • 11
  • I think you have to give us the information what are you doing in SAP. The part of the code you show is okay. I do not see any problem there. – Storax May 04 '18 at 10:06
  • Hi, it is not a problem with my code, i use similar code in other transactions and operations and it works out fine. The problem is with SAP or Excel, as SAP takes too long to complete the operation and Exce gives the error i made a screenshot of. So how can i make Excel not wait for the OLE... – M_Delineshev May 08 '18 at 06:23
  • 1
    Then maybe [this](https://stackoverflow.com/questions/44288799/how-to-deal-with-microsoft-excel-is-waiting-for-another-application-to-complete) helps – Storax May 08 '18 at 06:48
  • Thank you Storax! – M_Delineshev May 10 '18 at 14:27

3 Answers3

4

Storax 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
iDevlop
  • 24,841
  • 11
  • 90
  • 149
M_Delineshev
  • 115
  • 1
  • 3
  • 11
2

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
a_babich
  • 43
  • 1
  • 5
  • While this might answer the authors question, it lacks some explaining words and links to documentation. Raw code snippets are not very helpful without some phrases around it. You may also find [how to write a good answer](https://stackoverflow.com/help/how-to-answer) very helpful. Please edit your answer. – hellow Sep 24 '18 at 11:17
  • Where to paste this code? – Fennekin Jan 05 '22 at 19:03
  • In a module or in workbook's view code area? – Fennekin Jan 05 '22 at 19:04
0

This following code worked for me...

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

Sub IgnoreMessages()

Dim lMsgFilter As Long

CoRegisterMessageFilter 0&, lMsgFilter

'Write your code here

CoRegisterMessageFilter lMsgFilter, lMsgFilter

End Sub