1

I am trying to establish connection using SAP GUI from Excel VBA and keep getting the same 424 error.

Runtime Error 424 “Object Required”

I've tried multiple ways changing variables but nothing seems to be working for me :(

enter image description here

screenshot

If Not IsObject(Application) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set Applicationa = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
   Set Connection = Applicationa.Children(0)
End If
If Not IsObject(session) Then
   Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session, "on"
   WScript.ConnectObject Application, "on"
End If
session.findById("wnd[0]").resizeWorkingPane 131, 25, False
session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00006"
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Stas Pegov
  • 37
  • 5
  • Line number 7 "Set Connection = Applicationa.Children(0)" right after this one. I just reuploaded the image, marked in yellow. Thank you! – Stas Pegov Dec 21 '21 at 22:26
  • 2
    Notice that you use `Application` previously. Should that be `Applicationa`? – BigBen Dec 21 '21 at 23:28

1 Answers1

2

I guess the SAP GUI Scripting Engine is not activated on the client or server side, you can use this way to localize the problem:

On Error Resume Next ' note that you will need to check errors mannualy

'check SAPGUI is running
Dim guiSAP As Object: Set guiSAP = GetObject("SAPGUI")
    
If guiSAP Is Nothing Then
    MsgBox ("SAPGUI is not running!"), vbCritical, "SAP GUI"
    Exit Sub
End If

'check that scripting engine is activated
Dim appSAP As Object: Set appSAP = guiSAP.GetScriptingEngine

If appSAP Is Nothing Then
    MsgBox ("SAP GUI Engine is not activated!"), vbCritical, "SAP GUI Scripting"
    Exit Sub
End If

'check connection to SAP
Dim connectionSAP As Object: Set connectionSAP = appSAP.Children(0)

If connectionSAP Is Nothing Then
    MsgBox ("SAP connection lost!"), vbCritical, "SAP Connection"
    Exit Sub
End If

'check SAP session
Dim sessionSAP As Object: Set sessionSAP = connectionSAP.Children(0)

If sessionSAP Is Nothing Then
    MsgBox ("No Active SAP Session!"), vbCritical, "SAP Session"
    Exit Sub
End If
Vasily
  • 5,707
  • 3
  • 19
  • 34
  • Thank you so much @Vasily, it helped me to identify the first problem. After running the following line " MsgBox ("SAPGUI is not running!"), vbCritical, "SAP GUI" i get a pop up window "SAP GUI is not running" . Right now i am looking to fix that, I have already enabled SAP GUI API in VBA preferences, but still nothing. – Stas Pegov Dec 22 '21 at 09:43
  • @StasPegov "SAP GUI is not running" means that GUI not initialized, so you need to be logged in to SAP before running the script. – Vasily Dec 22 '21 at 11:52
  • i am logged in, but still get the same pop up. Well i will try to find a way to fix it. Thank you for helping me out! – Stas Pegov Dec 22 '21 at 13:36