VBA Excel SSO 到 SAP/运行时错误 70 "access denied"

VBA Excel SSO to SAP / runtime error 70 "access denied"

我花了几个小时来寻找问题。 我想用 ini 文件启动 SAP Logonpad,效果很好。 然后绑定到脚本对象后,我想打开到特定系统的连接,连接 = SapGui.OpenConnection("SID", True) 但总是出现运行时错误 70 访问被拒绝。

我遵循了其他人似乎用 vbs 做的事情,对于某些原因我不能用 vbs 做,必须用 vba,所以可能有一些不同导致它失败?

如有任何建议,我们将不胜感激。

    Private Sub CommandButton1_Click()


    Dim SapGui As Object

    Dim saplogon As Object

    Dim connection 'As Object



    Set SapGui = GetObject("SAPGUI")


    Dim Wshshell As Object


    Set Wshshell = CreateObject("Wscript.Shell")

    Wshshell.Run Chr(34) & ("C:\Program Files\SAPPC\FrontEnd\SAPgui
    \saplogon.exe") & Chr(34) & " " & "/INI_FILE" & "=" & Chr(34) & 
    "\longpathtoini\appl\Sap\saplogon\int\saplogon.ini" & Chr(34)

        Do Until Wshshell.AppActivate("SAP Logon")
            Application.Wait Now + TimeValue("0:00:01")
        Loop

    Set Wshell = Nothing


    Set saplogon = SapGui.GetScriptingEngine

    connection = SapGui.OpenConnection("SID", True)


    Set SapGui = Nothing

    Set saplogon = Nothing

    Set connection = Nothing


    End Sub

检查特定系统是否允许用户脚本(事务 RZ11,参数 sapgui/user_scripting)。另请注意,对于某些版本,您显然需要指定 SAP 登录条目文本而不是 SID。

感谢 vwegert。

我当然知道需要在服务器上启用脚本。 也就是说,但在我阅读他的回答的那一刻,我记得在我的 SAP GUI 设置中启用了 "Warn if a script tries to connect" 的复选框。

禁用选项确实导致了成功。

以上代码完美运行。