设置Connection=Application.OpenConnection使其他用户的Excel崩溃

设置Connection=Application.OpenConnection使其他用户的Excel崩溃,excel,sap,vba,Excel,Sap,Vba,我仔细检查了所有的参考资料是否匹配(它们确实匹配),Excel列在SAP中的应用程序下;但是,当其他人使用以下代码时,Excel会完全崩溃 如果我运行代码(按created按钮),Excel就会自动关闭。如果我单步执行,我会收到警告消息,即Excel在Set Connection=Application.OpenConnection(“Production”)行上没有响应。 进一步的代码继续 可能需要注意的是,这影响了另外两个用户,并于同一天(2018年4月26日)开始对他们两人进行测试。在此日

我仔细检查了所有的参考资料是否匹配(它们确实匹配),Excel列在SAP中的应用程序下;但是,当其他人使用以下代码时,Excel会完全崩溃

如果我运行代码(按created按钮),Excel就会自动关闭。如果我单步执行,我会收到警告消息,即Excel在
Set Connection=Application.OpenConnection(“Production”)行上没有响应。

进一步的代码继续


可能需要注意的是,这影响了另外两个用户,并于同一天(2018年4月26日)开始对他们两人进行测试。在此日期之前,双方都没有问题。但是,我运行的代码没有任何问题。此外,“生产”也被用来代替实际描述。

也许使用
Dim应用程序作为SAPFEWSELib不是一个好主意。GuiApplication
作为
应用程序
通常是Excel本身的参考。也许您可以尝试将Dim GuiAppl设置为SAPFEWSELib.GuiApplication。但我猜是因为你的代码对我有用。这实际上解决了问题。非常感谢你的帮助。
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