0

I have double checked all references match (they do) and Excel is listed under Applications in SAP; however, when others use the following code, Excel completely crashes.

If I run the code (pressing the created button), Excel just closes itself. If I step through, I receive the warning message that is Excel is not responding on the line Set Connection = Application.OpenConnection("Production").

Private Sub CommandButton1_Click()
    strVar = InputBox("Which Path?" & vbNewLine & vbNewLine & "1 - DC to Copack" & vbNewLine & vbNewLine & "2 - Copack to DC" & vbNewLine)
    Sheet1.Cells.Clear

    Call DeleteRepl

    Dim SapGuiAuto As Object
    Dim Application As SAPFEWSELib.GuiApplication
    Dim Connection As SAPFEWSELib.GuiConnection
    Dim i As Integer
    Dim Conn As String
    Dim Flag As Boolean

    Flag = False

    If Not IsObject(SAPguiAPP) Then
        Set SAPguiAPP = CreateObject("Sapgui.ScriptingCtrl.1")
    End If

    Set SapGuiAuto = GetObject("SAPGUI")
    Set Application = SapGuiAuto.GetScriptingEngine

    If Application.Connections.Count() > 0 Then
        For i = 0 To Application.Connections.Count() - 1
            Set Connection = Application.Children(i)
            Conn = Connection.Description()
            If Conn = "Production" Then
                Flag = True
                Exit For
            End If
        Next

        If Flag = False Then
            Set Connection = Application.OpenConnection("Production")
        End If

        If Not IsObject(Session) Then
            Set osession = Connection.Children(0)
        End If

Further code continues.

Probably important to note, this is affecting two other users and began on the same day (April 26, 2018) for both of them. Neither had issues prior to this date. However, I am having zero issues with the code running for me. Also, "Production" is being used in replace of the actual Description.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 1
    Maybe it's not a good idea to use `Dim Application As SAPFEWSELib.GuiApplication` as `Application`is usually a reference to Excel itself. Maybe you try `Dim GuiAppl As SAPFEWSELib.GuiApplication`. But I am guessing because your code is working for me. – Storax May 04 '18 at 09:58
  • This actually resolved the issue. Thank you so much for the assistance. – josh cunningham May 09 '18 at 21:06

0 Answers0