Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub SAPGUI_New()
- Dim OpenNewConnFlag
- Dim Application, SAPGUI, Connection, SapGuiAuto, WScript, Session, wshShell, oExec
- OpenNewConnFlag = False
- If Not IsObject(Application) Then
- On Error Resume Next
- 'If the script can't get the object, it starts saplogon
- 'and try to get the object again.
- Set SapGuiAuto = GetObject("SAPGUI")
- If Err.Number <> 0 Then
- On Error GoTo 0
- Set wshShell = CreateObject("WScript.Shell")
- Set oExec = wshShell.Exec("c:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe")
- On Error GoTo 0
- Do While Not wshShell.AppActivate("SAP Logon 730")
- 'WScript.Sleep 500
- Loop
- Set SapGuiAuto = GetObject("SAPGUI")
- Else
- On Error GoTo 0
- End If
- Set Application = SapGuiAuto.getScriptingEngine
- End If
- If Not IsObject(Connection) Then
- On Error Resume Next
- 'If the script can't open connection 0, it opens a
- 'new connection
- Set Connection = Application.OpenConnection("G4P GCF/Cons Prod", True)
- If Err.Number <> 0 Then
- On Error GoTo 0
- Application.OpenConnectionByConnectionString _
- "/H/10.100.200.100/S/3200", True
- OpenNewConnFlag = True
- Else
- On Error GoTo 0
- OpenNewConnFlag = True
- End If
- 'Set Connection = Application.OpenConnection("G4P GCF/Cons Prod", True)
- End If
- If Not IsObject(Session) Then
- Set Session = Connection.Children(0)
- 'If the script opens a new connection, it logon to the system
- If OpenNewConnFlag = True Then
- With Session
- Dim user
- Dim pass
- username = username.Text
- pass = password.Text
- .findById("wnd[0]/usr/txtRSYST-BNAME").Text = username
- .findById("wnd[0]/usr/pwdRSYST-BCODE").Text = pass
- .findById("wnd[0]").sendVKey 0
- '======
- On Error Resume Next
- .findById("wnd[1]/usr/radMULTI_LOGON_OPT1").Select
- If Err.Number <> 0 Then
- On Error GoTo 0
- Else
- .findById("wnd[1]/usr/radMULTI_LOGON_OPT1").SetFocus
- .findById("wnd[1]/tbar[0]/btn[0]").press
- End If
- End With
- End If
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement