Skip to Content
avatar image
Former Member

Selecting the active window with SAP GUI Scripting being run by HTA

The code below works fine if I'm using a hotkey to launch the script.

The problem comes when I'm trying to launch the script using HTA. I get an error saying "Object required: 'session'".

How can I fix this? I need to be able to choose which sap session to run the script on while launching with HTA.

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
msgbox "Please select a session to run the script on", vbSystemModal
set session = application.ActiveSession
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Nov 03, 2016 at 09:58 AM

    My Suggestion:

    . . .
    <script type="text/vbscript">
     Sub SAP_Script()
      set wshell = CreateObject("Wscript.Shell")
      myCur = wshell.CurrentDirectory 
      wshell.run "c:\windows\system32\wscript.exe" & " " & myCur & "\test.vbs"
     End Sub
    </script>
    . . .
    

    test.vbs:

     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
     msgbox "Please select a session to run the script on", vbSystemModal
     set session =application.ActiveSession
    
    
    Add comment
    10|10000 characters needed characters exceeded