Set Connection = Application.OpenConnection为其他用户崩溃Excel

时间:2018-05-02 20:05:40

标签: excel-vba sap vba excel

我已经仔细检查了所有引用匹配(他们这样做),Excel列在SAP中的应用程序中;但是,当其他人使用以下代码时,Excel完全崩溃。

如果我运行代码(按下创建的按钮),Excel就会自动关闭。如果我单步执行,则会收到Excel在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

进一步的代码继续。

可能需要注意的是,这会影响另外两个用户并在同一天(2018年4月26日)开始。在此日期之前都没有问题。但是,我运行的代码没有问题。此外,“生产”用于替换实际描述。

0 个答案:

没有答案