Excel SAP GUI - Automation Error Invalid Syntax

1.4k views Asked by At

I logged into my SAP GUI and recorded a basic process to test using SAP GUI script recording option. After that I went to excel and wrote the following code. When I run it, I get the error :

Run-time error'-2147221020(800401e4): Automation error Invalid syntax

Not sure why this is happening.

EDIT Oct 8th, 2022 (pasted from OP comments): "[SAP GUI is] running on virtual machine [...] Both SAP and Excel are running on the same machine (my laptop) [...] SAP [GUI] is installed on my local machine"

VBA CODE:

Option Explicit
Public SapGuiAuto
Public objGui As GuiApplication
Public objConn As GuiConnection
Public session As GuiSession

Sub SAPCustomerReport()

Set SapGuiAuto = GetObject("SAPGUI")
Set objGui = SapGuiAuto.GetScriptingEngine
Set objConn = objGui.Children(0)
Set session = objConn.Children(0)
 
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").selectedNode = "F00004"
session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00004"
session.findById("wnd[0]/usr/ctxtRIWO00-QMART").Text = "d1"
session.findById("wnd[0]/usr/ctxtRIWO00-QMART").caretPosition = 2
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[15]").press
session.findById("wnd[1]/usr/btnSPOP-OPTION2").press

MsgBox "Script Complete"

End Sub

0

There are 0 answers