Skip to Content
Oct 15, 2020 at 09:25 PM

Excel Error Method "FindById" of object "ISapSession Target" Failed

442 Views Last edit Oct 16, 2020 at 10:22 AM 2 rev

Hi everyone,

I'm trying to open notification from excel to pull some data. I'm using the GUI script with VBA, but when I try to enter the notification number the script fails. and I get this error message:

This is my code:

Sub SapConn()

Dim Appl As Object
Dim Connection As Object
Dim session As Object
Dim WinShell As Object
Dim SapGui As Object

'C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe SAP Location
Shell "C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe", 4
Set WshShell = CreateObject("WScript.Shell")

Do Until WshShell.AppActivate("SAP Logon ")
    Application.Wait Now + TimeValue("0:00:10")

Set WshShell = Nothing
Set SapGui = GetObject("SAPGUI")
Set Appl = SapGui.GetScriptingEngine
'In the following line change the name of the medule Appl.Openconnection("paste name of module", ...
Set Connection = Appl.Openconnection("PAE - ECC All Business Functions", True)
Set session = Connection.Children(0)

'Username and Password
'save the user and password in a string variable before run SAP
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "050"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "cedilloj"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "Carlos@93"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

If session.Children.Count > 1 Then

    answer = MsgBox("You've got opened SAP already," & _
"please leave and try again", vbOKOnly, "Opened SAP")


    Exit Sub

End If

'Enter into the transaccion code iw53
session.findById("wnd[0]/tbar[0]/okcd").Text = "iw53"
session.findById("wnd[0]").sendVKey 0
Application.Wait DateAdd("s", 5, Now)

'Enter Notification
session.findById("wnd[0]/usr/ctxtRIWO00-QMNUM").Text = "303059606"
UserArea.findById("/app/con[0]/ses[0]/wnd[0]").sendVKey 0

End Sub