runtime error '91' bex analyzer code example

runtime error '91' bex analyzer

1

1 Example

0
    Public session As Object

Function GetSession() As Boolean
    Dim IE As InternetExplorerMedium
    Dim Created_IE As Boolean
    Dim Sh As New Shell32.Shell
    Dim ShellWindow As Object
    Dim OpenWindows As Integer: OpenWindows = 0
    Dim OpenSessions As Integer
    Dim LoopCount As Integer: LoopCount = 0
    Dim SAPSession_Known As Boolean: SAPSession_Known = False
    Dim SAPGuiScripting As Object
    Dim SAPApplication As Object
    Dim SAPConnection As Object
    Dim SAPSession As Object

    ' Loop through all open windows to bring the SAP Portal into focus
    For Each ShellWindow In Sh.Windows
        ' Find the Window with the desired SAP Portal URL
        If InStr(1, LCase$(ShellWindow.LocationURL), "com.sap.portal.appintegrator.sap.Transaction") Then
            ' Count the number of open SAP Sessions
            OpenWindows = OpenWindows + 1
        End If
DoEvents
    Next ShellWindow


    Do Until SAPSession_Known = True Or LoopCount > 100
On Error Resume Next
        Set SAPGuiScripting = GetObject("SAPGUI")
        Set SAPApplication = SAPGuiScripting.GetScriptingEngine

On Error GoTo 0
        If OpenWindows = 0 Then

On Error Resume Next
            Set SAPConnection = SAPApplication.Children(0)
On Error GoTo 0
On Error Resume Next
            Set SAPSession = SAPConnection.Children(0)
On Error GoTo 0

        Else

On Error Resume Next
            Set SAPConnection = SAPApplication.Children(Int(OpenWindows - 1))
On Error GoTo 0
On Error Resume Next
            Set SAPSession = SAPConnection.Children(Int(OpenWindows - 1))
On Error GoTo 0

        End If
DoEvents
On Error Resume Next
        OpenSessions = SAPApplication.Children.Count
On Error GoTo 0

        If (OpenSessions <> 0) And Not (SAPSession Is Nothing) Then SAPSession_Known = True
    Loop

On Error Resume Next
    AppActivate ("com.sap.portal.appintegrator.sap.Transaction")
On Error GoTo 0

    If SAPSession Is Nothing Then
        MsgBox "SAP session not found"
        GetSession = False
    Else
        Set session = SAPSession
        GetSession = True
    End If
End Function

Other Code Examples