Sap系统和vba的简单介绍
怎样通过VBA连接SAP
因为很多非basis想做这方面的接口调用,根据我自己的经验提示一下,也许不适合所有的人。只要你有可以登录SAP的权限,应该就可以连接。技巧是先不要用静连接,也就是把连接语句的TRUE,改成0,这样连接时会调出连接设置界面,里面很多信息都有默认值。特别是楼主说的number问题,你点不同的服务器名,就看到不同的number了。另外,开始我不知道IP地址,服务器在国外,我用这个办法,故意在vba里写一个错误命令,搞到IP地址的。
网站建设哪家好,找成都创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了尼玛免费建站欢迎大家使用!
VBA 调用 SAP RFC 报错
使用VBA调用SAP RFC和JCO 常用的方法基本一致,大致分为三步:登录系统,执行RFC函数,注销
示例代码
Sub Macro1()
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = "DEV"
R3.Connection.ApplicationServer = "172.18.28.5"
R3.Connection.Client = "700"
R3.Connection.SystemNumber = "00"
R3.Connection.User = "ZHANGXB"
R3.Connection.Password = "密码"
R3.Connection.Language = "ZH"
R3.Connection.Codepage = "8400"
If R3.Connection.logon(0, True) = True Then
MsgBox "连接成功"
Else
MsgBox "连接不成功"
End If
Set MyFunc = R3.Add("ZGET_KPI")
Set zmonth = MyFunc.Tables("T_ZYRMONTH")
zmonth.AppendRow
zmonth(1, "SIGN") = "I"
zmonth(1, "OPTION") = "EQ"
zmonth(1, "LOW") = "200910"
Result = MyFunc.CALL
Set T_KPI = MyFunc.Tables("T_KPI")
For i = 1 To zmonth.Rows.Count
MsgBox T_KPI(1, "KPI_VALUE")
Next i
End Sub
R3.Connection.LOGOFF
通过EXCEL VBA 连接SAP系统后,导出打开的电子表格文件另存(不是系统自带的导出EXCEL表)
没太看明白你的需求,是不是说,vba已经控制sap界面表单,提交后,导数数据为excel,然后你想打开那个excle,录制的时候无法办到是吗?
那确实是无法操控的,因为超过sap录制的范围了,sap只录制sap里面的操作。如果要操作接下来导出的excel文件,很简单,因为导入文件的路径和地址都是已知的,直接在vba中 Set ak = Workbooks.Open(wb, UpdateLinks:=0)打开这个导出的excel不就行了。
如何通过excelVBA进去SAP系统提取相关
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 查看原帖
名称栏目:Sap系统和vba的简单介绍
链接分享:http://cdiso.cn/article/dopejgd.html