没太看明白你的需求,是不是说,vba已经控制sap界面表单,提交后,导数数据为excel,然后你想打开那个excle,录制的时候无法办到是吗?
成都创新互联主要从事网站设计、成都做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务滑县,十载网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220
那确实是无法操控的,因为超过sap录制的范围了,sap只录制sap里面的操作。如果要操作接下来导出的excel文件,很简单,因为导入文件的路径和地址都是已知的,直接在vba中 Set ak = Workbooks.Open(wb, UpdateLinks:=0)打开这个导出的excel不就行了。
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 查看原帖
因为很多非basis想做这方面的接口调用,根据我自己的经验提示一下,也许不适合所有的人。只要你有可以登录SAP的权限,应该就可以连接。技巧是先不要用静连接,也就是把连接语句的TRUE,改成0,这样连接时会调出连接设置界面,里面很多信息都有默认值。特别是楼主说的number问题,你点不同的服务器名,就看到不同的number了。另外,开始我不知道IP地址,服务器在国外,我用这个办法,故意在vba里写一个错误命令,搞到IP地址的。