Skip to Content
0
Oct 28, 2019 at 08:32 AM

Trying SAP GUI SCRIPTING in VBA but Excel can't find session. What's causing this?

307 Views Last edit Oct 27, 2019 at 11:36 PM 2 rev

Hello,

I am wanting to automate some stuff in SAP through VBA. For now, I am trying to execute the following code:

  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

The last line is resulting in a error: "Run-time error '614'". I placed SAPCon in the watch window but it has a count of 0 for sessions. Despite SAP Easy Access being open in the background. The rest of the lines execute fine.

Also, GUI scripting is enabled on my local computer but not the server. But, I looked at the documentation and it said I can still scripts, just not record them. If this is what's causing the issues then I wonder if I can use SAP's ActiveX libraries instead? I have no way of getting GUI scripting enabled on the server side.

Any help is appreciated.