on 11-01-2016 7:33 PM - last edited on 02-03-2024 7:01 PM by postmig_api_4
Hi experts.
Can you help me to convert this macro to vbs script.
This macro is to select the last sap session.
Option Explicit
Sub test()
Dim SapGuiApp As Object
Dim oConnection As Object
Dim Session As Object
Dim SAPCon As Object, SAPSesi As Object
Dim SAPGUIAuto As Object, SAPApp As Object
Dim NumOfRows As Long
Dim Counter As Long
Dim SAP As Object, SAPGUI As Object, SAPConnections As Object
Dim cntConnection As Long, i As Long, SAPConnection As Object
Dim Sessions As Object, cntSession As Long, j As Long
Dim SessionExists As Boolean
Application.ScreenUpdating = False
NumOfRows = ActiveSheet.UsedRange.Rows.Count - 3
SessionExists = False
On Error Resume Next
Set SAP = GetObject("SAPGUI")
If Not IsObject(SAP) Then
Exit Sub
End If
Set SAPGUI = SAP.GetScriptingEngine
If Not IsObject(SAPGUI) Then
Exit Sub
End If
Set SAPConnections = SAPGUI.Connections()
If Not IsObject(SAPConnections) Then
Exit Sub
End If
cntConnection = SAPConnections.Count()
For i = 0 To cntConnection - 1
Set SAPConnection = SAPGUI.Connections(CLng(i))
If IsObject(SAPConnection) Then
Set Sessions = SAPConnection.Sessions()
If IsObject(Sessions) Then
cntSession = Sessions.Count()
For j = 0 To cntSession - 1
Set Session = SAPConnection.Sessions(CLng(j))
If IsObject(Session) Then
SessionExists = True
End If
Next j
End If
End If
Next i
If SAPConnection Is Nothing Then
MsgBox "Error.. no SAP session could be found"
Exit Sub
End If
With Session
.findById("wnd[0]").maximize
.findById("wnd[0]/tbar[0]/okcd").Text = "/nfbl3n"
End With
End Sub
credits to
stefan.schnell
johann.strohstefan.schnell
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.