VBA Excel SSO到SAP /运行时错误70“拒绝访问”

我花了几个小时find问题。 我想用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 )。 另请注意,对于某些版本,显然需要指定SAPlogin条目文本而不是SID。

感谢vwegert。

我当然知道需要在服务器上启用脚本。 这是,但是现在我读了他的答案,我记得在我的SAP GUI设置中,“如果脚本试图连接的警告”checkbox已启用。

放弃这个select,确实导致了成功。

上面的代码完美地工作。