怎样通过VBA连接SAP

怎样通过VBA连接SAP,第1张

因为很多非basis想做这方面的接口调用,根据我自己的经验提示一下,也许不适合所有的人。只要你有可以登录SAP的权限,应该就可以连接。技巧是先不要用静连接,也就是把连接语句的TRUE,改成0,这样连接时会调出连接设置界面,里面很多信息都有默认值。特别是楼主说的number问题,你点不同的服务器名,就看到不同的number了。另外,开始我不知道IP地址,服务器在国外,我用这个办法,故意在vba里写一个错误命令,搞到IP地址的。

Private Sub CommandButton1_Click()Dim Functions As ObjectDim func As ObjectDim iTable As Object' Create the Function control (that is, the high-level Functions collection):Set oFunction = CreateObject("SAP.LogonControl.1")Set oConnection = oFunction.NewConnectionoConnection.client = "100"oConnection.Language = "EN"oConnection.user = "username"oConnection.Password = "password"oConnection.ApplicationServer = "10.1.0.1"oConnection.SystemNumber = "00"result = oConnection.Logon(0, True)Set ofun = CreateObject("SAP.FUNCTIONS")Set ofun.Connection = oConnectionSet func = ofun.Add("ENQUEUE_READ")' Set the export parameters (here, get all customers whose names start with J):func.Exports("GCLIENT") = "100"func.Exports("GUNAME") = ""func.Exports("LOCAL") = "0"Set iTable = func.Tables("ENQ")' Call the function (if the result is false, then display a message):If func.Call = True ThenSet iTable = func.Tables("ENQ") 'ENQ is the internal tableget_data iTableMsgBox "Get Data OK!"ElseMsgBox " Call Failed! error: " '+ func.ExceptionEnd IfoConnection.LogoffEnd SubPublic Sub get_data(itabtable As Object)Dim vField As VariantStatic j As IntegerFor j = 1 To itabtable.RowCountThisWorkbook.Sheets(4).Cells(j, 4) = itabtable.Value(j, "GNAME") '任何一个栏位名称ThisWorkbook.Sheets(4).Cells(j, 5) = itabtable.Value(j, "GUSR")ThisWorkbook.Sheets(4).Cells(j, 6) = itabtable.Value(j, "GUSRVB")NextEnd Sub 查看原帖>>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9439843.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存