1

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

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • Usually you get this error in case SAPGUI is not running or installed on the system you are running the code. But you are saying that you recorded the code on that very system, right? In this case you need to start SAPGUI first. Anyway, the whole code expects that you are logged on to a system. Reading [1](https://help.sap.com/docs/sap_gui_for_windows?version=760.02&locale=en-US) [2](https://stackoverflow.com/questions/71624238/find-sap-gui-session-opened-for-given-sap-system/71626050#71626050) – Storax Oct 03 '22 at 06:33
  • Please post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Sandra Rossi Oct 03 '22 at 08:08
  • Thank you for your response. I updated my post with my entire code – marsprogrammer Oct 03 '22 at 13:46
  • 2
    Does this answer your question? [Connect SAP on Citrix through Excel VBA](https://stackoverflow.com/questions/41543972/connect-sap-on-citrix-through-excel-vba) – Storax Oct 03 '22 at 17:20
  • I edited your question to include the important comments about SAP GUI installed and running on the virtual machine and Excel installed and running on your laptop, although how you say it is confusing. – Sandra Rossi Oct 08 '22 at 08:14

0 Answers0