我花了几个小时找问题。我想用ini文件启动,这很好。然后,在绑定到脚本对象之后,我想打开连接到特定系统的连接,连接= 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发布于 2016-05-22 09:01:04
多亏了维格特。
我当然知道脚本需要在服务器上启用。这就是,但在我读到他的答案时,我记得在我的SAP GUI设置中启用了“如果脚本试图连接就警告”的复选框。
抛弃那些选择确实会导致成功。
上面的代码工作得很好。
https://stackoverflow.com/questions/37236396
复制相似问题