0

Perhaps someone with experience in SAP GUI and VBScripts can help me.

I am trying to run the following VBScript in SAP GUI

If Not IsObject(application) Then
    Set SapGuiAuto = GetObject("SAPGUI")
    Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
    Set connection= application.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]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text="cv04n"
session.findById("wnd[0]").sendVkey 0

I keep getting the error:

The server threw an exception. Code: 80010105

This error is in this line: session.findById("wnd[0]").maximize.

Can the server block my scripts?

The SAP GUI scripts are enabled in the SAP GUI configuration, but when I try to record one it doesn't record and the symbol down in the window always says that script is running but nothing happens and doesn't record anything to the .vbs file.

When I try to run my script inside the GUI the same happens and it will stay running but nothing happens.

Thank you very much.

4

1 Answer 1

0

This :

 Set application = SapGuiAuto.GetScriptingEngine

Because of this , You will never be able to get scripting engine of SAP , "Application" belongs to Excel, You can not set it to external application.

Change it to :

 Set sapapplication = SapGuiAuto.GetScriptingEngine

Let me give you Full Code example :

   Set sapguiauto = GetObject("SAPGUI")
   Set sapapplication = sapguiauto.GetScriptingEngine
   Set connection = sapapplication.Children(0)
   Set session = connection.Children(0)

Now you have SAP Session. Do anything with it.

Like :

session.findById("wnd[0]/sbar").Text
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text="cv04n"
session.findById("wnd[0]").sendVkey 0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.