'SAP GUI Scripting can't playback the created .vbs file

Sup guys,

I've been trying to automate some repetitive tasks in SAP via the Scripting GUI. I've got the necessary authorization in RZ11 and I can record and create a .vbs file. When I press the Playback button, it opens a window to select a file everytime I try to playback a file.

So it's basically just a loop of choosing a file but it doesn't execute. You can see the code down below. It's a simple script that opens a specific file.

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 = "/npsobwork"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtSPSOB001FLDS-PSOBKEY").text = "501020003838"
session.findById("wnd[0]/usr/ctxtSPSOB001FLDS-PSOBKEY").caretPosition = 12
session.findById("wnd[0]").sendVKey 0

Anyone else had a problem like this? Our IT dep. has just found out about the Scripting GUI so they aren't a help either :(



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source