SAP GUI版本:740; EXCEL:2016(64X)
我可以使用以下代码(示例参数)通过VBA连接到SAP:
Dim sapLogon As SAPLogonCtrl.SAPLogonControl
Dim sapConn As SAPLogonCtrl.Connection
Public Sub Logon()
Set sapLogon = New SAPLogonControl
Set sapConn = sapLogon.NewConnection
With sapConn
.System = "PRP"
.ApplicationServer = "123.456.789.12"
'.SAPRouter = "/H/123.456.789.24/S/3299/H/" 'comment this line
.SystemNumber = "00" '
.Client = "100"
.User = "user"
.Password = "mypassword"
.Language = "EN"
End With
Call sapConn.Logon(0, True)
If sapConn.IsConnected <> tloRfcConnected Then
MsgBox "connectiong failed." & sapConn.IsConnected
Exit Sub
Else
MsgBox "connecting successful"
End If
End Sub
我想连接另一个不在同一域中的SAP系统SID:“ P95”。因此,我使用SAPRouter参数,删除注释行
.SAPRouter = "/H/123.456.789.24/S/3299/H/" 'the value is copy form SAP GUI with 'P95'
它无法连接'P95',结果是'连接g失败。 8'
我想原因是“ P95”中的安全策略
但是奇怪的是,如果我更改代码:
Call sapConn.Logon(0,True)
到
Call sapConn.Logon(0,False)
并注释该行
.SAPRouter = "/H/123.456.789.24/S/3299/H/"
然后在“ SAP登录”对话框中选择SAP系统:“ P95”并输入我的密码,
它可以登录“ P95”
我还发现TAB“服务器”具有第一个SAP SID配置的填充值(我的SAP GUI有许多SAP SID)
那么,如何解决此问题,或者我们无法通过这种方式连接SAP。
谢谢。