This Macro will never open a SAP Window - it will create an SAP-Object within VBA where you can work with SAP-RFC-Functions.
(该宏永远不会打开SAP窗口-它将在VBA中创建一个SAP对象,您可以在其中使用SAP-RFC-Functions。)
(Reading Data from SAP, Writing Data into SAP) ((从SAP读取数据,将数据写入SAP))
In your version the SAP connection will be unaccessible after "End Sub".
(在您的版本中,在“ End Sub”之后将无法访问SAP连接。)
You have to declair the Object outside the sub. (您必须在子对象外部对对象进行装饰。)
This works silent (without dialog) for me:
(这对我来说是静音的(无对话框):)
Dim sap As Object
Public Function login1() As Boolean
Set sap = CreateObject("SAP.Functions")
sap.Connection.System = "System Test Environment"
sap.Connection.client = "100"
sap.Connection.user = "user"
sap.Connection.Password = "password"
sap.Connection.Language = "EN"
If sap.Connection.logon(0, False) <> True Then
sap.RemoveAll
MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
Else
login1 = true
End If
End Function
Public Function SAPLogoff()
On Error Resume Next
sap.RemoveAll
sap.Connection.logoff
LoggedOn = False
Set sap = Nothing
'Set conn = Nothing
End Function
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…