Skip to Content

Excel waiting for an OLE Action, while running an SAP script

Hello everyone,

I am fairly new to SAP scripting, but have some experience with VBA already. i have the following issue trying to automate a process in SAP for my current position. So i am recording a series of procedures, pasting the code in a macro sheet and make the Excell read the VBS code with the following commands:

Dim SapGuiAuto AsObject
Dim Application AsObject
Dim Connection AsObject
Dim Session AsObject

Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
Set Connection = Application.Children(0)
Set Session = Connection.Children(0)

So all is fine, but for one of the parts SAP makes a lot of calculations which takes a few minutes and around the middle of it, Excel generate the message:

So i have to click OK in order to continue, which is annoying because then it pops-up non-stop and i have to do it like 10-15 times in order to reach the goal, 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, but it would not works, instead gives me:

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

1. My laptop is from work and i cannot install any additional software or updates to it without permission so please give me alternative solutions if you had that in mind.

2.I tried checking the Excel option for DDE, but it only gives me an error when i try to run the script:

3. Excel is 2013, SAP -ABAB.

So, can anyone help me 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 apears

3. make Excel freeze and wait while SAP does its thing? (don't know if that makes sense..) - BTW, Tried with Application.Wait, but without success

I really hope someone can help me out here,

Thank you in advance,


ole.jpg (6.6 kB)
error.png (13.1 kB)
i7ygd.png (2.3 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    May 13, 2018 at 11:58 AM

    Hi all,

    i actually found a good solution in Stackoverflow. So for anyine having a similar issue:

    Add comment
    10|10000 characters needed characters exceeded

  • May 03, 2018 at 09:02 AM

    Hi Mihail,

    "Application" is a protected word in VBA. You could use the following instead:

    Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
    Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
    Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
    Set session = SAPCon.Children(0) 'Get the first session (window) on that connection



    Add comment
    10|10000 characters needed characters exceeded

  • May 03, 2018 at 11:24 AM

    Hi ScriptMan,

    thanks for the suggestion, however i cannot remove the declaration of Application. When i paste the code from the recorded script, the word Application is embedded within the code:

    If Not IsObject(Application) Then Set SapGuiAuto = GetObject("SAPGUI") Set Application = SapGuiAuto.GetScriptingEngine

    Or should i additionally change something to that code?

    Add comment
    10|10000 characters needed characters exceeded

    • If you're porting the recorded script to VBA, it's best to skip the first 14 lines completely and use the ones I've recommended above. You add the remaining lines of the recorded script to it, of course.