Skip to Content

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

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")
Loop


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")


    session.findById("wnd[1]/usr/radMULTI_LOGON_OPT3").Select
    session.findById("wnd[1]/usr/radMULTI_LOGON_OPT3").SetFocus
    session.findById("wnd[1]/tbar[0]/btn[0]").press


    Exit Sub


End If


'Enter into the transaccion code iw53
'session.findById("wnd[0]").maximize
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


Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Oct 16 at 04:41 AM

    Hello Jose,

    your code looks good. I tested it in my environment and it works without problems. So I assume that your Network Settings are set to Low Speed Connection, but it must be set to High Speed Connection. Take a right click with the mouse pointer in the SAP Logon on the SAP system, where you want to execute your script, and choose Properties..

    Switch to Network tab and set the Network Settings to High Speed Connection.

    Let us know your results.

    Best regards
    Stefan


    lowspeed.jpg (82.7 kB)
    lowspeed1.jpg (49.8 kB)
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.