当前位置:   article > 正文

SAP script 自动创建销售订单机器人,协同Excel_sap script拉报表

sap script拉报表

首先要开启SAP的脚本 参考 ​​​​​​SAP系统开启脚本录制和回放功能 - 简书

参考一边生成销售订单的过程 注意不要有额外的操作 记录下脚本

  1. If Not IsObject(application) Then
  2. Set SapGuiAuto = GetObject("SAPGUI")
  3. Set application = SapGuiAuto.GetScriptingEngine
  4. End If
  5. If Not IsObject(connection) Then
  6. Set connection = application.Children(0)
  7. End If
  8. If Not IsObject(session) Then
  9. Set session = connection.Children(0)
  10. End If
  11. If IsObject(WScript) Then
  12. WScript.ConnectObject session, "on"
  13. WScript.ConnectObject application, "on"
  14. End If
  15. session.findById("wnd[0]").maximize
  16. session.findById("wnd[0]/tbar[0]/okcd").text = "va01"
  17. session.findById("wnd[0]").sendVKey 0
  18. session.findById("wnd[0]/usr/ctxtVBAK-AUART").text = "ZTA"
  19. session.findById("wnd[0]/usr/ctxtVBAK-VKORG").text = "1000"
  20. session.findById("wnd[0]/usr/ctxtVBAK-VTWEG").text = "20"
  21. session.findById("wnd[0]/usr/ctxtVBAK-SPART").text = "00"
  22. session.findById("wnd[0]/usr/ctxtVBAK-SPART").setFocus
  23. session.findById("wnd[0]/usr/ctxtVBAK-SPART").caretPosition = 2
  24. session.findById("wnd[0]").sendVKey 0
  25. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").text = "1 1"
  26. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:SAPMV45A:4701/ctxtKUAGV-KUNNR").text = "100002"
  27. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:SAPMV45A:4701/ctxtKUWEV-KUNNR").text = "100002"
  28. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").setFocus
  29. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").caretPosition = 3
  30. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/btnBT_HEAD").press
  31. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09").select
  32. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").text = "123" + vbCr + ""
  33. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").setSelectionIndexes 3,3
  34. session.findById("wnd[0]/tbar[0]/btn[3]").press
  35. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/ctxtVBKD-BSTDK").text = "20211201"
  36. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,0]").text = "12341"
  37. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3,0]").text = "2"
  38. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3,0]").setFocus
  39. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3,0]").caretPosition = 19
  40. session.findById("wnd[0]").sendVKey 0
  41. session.findById("wnd[0]/tbar[1]/btn[18]").press
  42. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-POSNR[0,0]").setFocus
  43. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-POSNR[0,0]").caretPosition = 4
  44. session.findById("wnd[0]").sendVKey 2
  45. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09").select
  46. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").text = "123" + vbCr + ""
  47. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").setSelectionIndexes 3,3
  48. session.findById("wnd[0]/tbar[0]/btn[3]").press
  49. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,1]").text = "12341"
  50. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3,1]").text = "3"
  51. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3,1]").setFocus
  52. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3,1]").caretPosition = 19
  53. session.findById("wnd[0]").sendVKey 0
  54. session.findById("wnd[0]").sendVKey 0
  55. session.findById("wnd[0]/tbar[1]/btn[18]").press
  56. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-POSNR[0,1]").setFocus
  57. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-POSNR[0,1]").caretPosition = 4
  58. session.findById("wnd[0]").sendVKey 2
  59. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").text = "123" + vbCr + ""
  60. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").setSelectionIndexes 3,3
  61. session.findById("wnd[0]/tbar[0]/btn[11]").press
  62. Cells(5, 1) = session.findById("wnd[0]/sbar").text

新建一个excel  进入开发工具,把上面的脚本拖入到里面 ,

加入Sub runva01()

末尾加入 end sub 

编辑Excel表格 

注意:表格的内容是指你要输入SAP 销售订单 的内容 

修改一下脚本如下:

  1. Sub runva01()
  2. Dim i, j, itemi, itemj, randx, strp, modvalue
  3. itemi = Cells(1, 3)
  4. itemj = Cells(1, 5)
  5. modvalue = Cells(4, 9)
  6. If Not IsObject(sapapplication) Then
  7. Set SapGuiAuto = GetObject("SAPGUI")
  8. Set sapapplication = SapGuiAuto.GetScriptingEngine
  9. End If
  10. If Not IsObject(connection) Then
  11. Set connection = sapapplication.Children(0)
  12. End If
  13. If Not IsObject(session) Then
  14. Set session = connection.Children(0)
  15. End If
  16. If IsObject(WScript) Then
  17. WScript.ConnectObject session, "on"
  18. WScript.ConnectObject sapapplication, "on"
  19. End If
  20. session.findById("wnd[0]").maximize
  21. session.findById("wnd[0]/tbar[0]/okcd").text = "va01"
  22. session.findById("wnd[0]").sendVKey 0
  23. session.findById("wnd[0]/usr/ctxtVBAK-AUART").text = "ZTA"
  24. session.findById("wnd[0]/usr/ctxtVBAK-VKORG").text = "1000"
  25. session.findById("wnd[0]/usr/ctxtVBAK-VTWEG").text = "20"
  26. session.findById("wnd[0]/usr/ctxtVBAK-SPART").text = "00"
  27. session.findById("wnd[0]/usr/ctxtVBAK-SPART").setFocus
  28. session.findById("wnd[0]/usr/ctxtVBAK-SPART").caretPosition = 2
  29. session.findById("wnd[0]").sendVKey 0
  30. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").text = Cells(4, 4)
  31. session.findById("wnd[0]").sendVKey 0
  32. session.findById("wnd[0]").sendVKey 0
  33. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:SAPMV45A:4701/ctxtKUAGV-KUNNR").text = Cells(4, 6)
  34. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:SAPMV45A:4701/ctxtKUWEV-KUNNR").text = Cells(4, 7)
  35. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").setFocus
  36. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").caretPosition = 3
  37. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/btnBT_HEAD").press
  38. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09").select
  39. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").text = Cells(4, 8)
  40. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").setSelectionIndexes 3, 3
  41. session.findById("wnd[0]/tbar[0]/btn[3]").press
  42. session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/ctxtVBKD-BSTDK").text = Cells(4, 5)
  43. For i = itemi To itemj
  44. j = i - itemi
  45. While j >= modvalue
  46. j = j - modvalue + 1
  47. Wend
  48. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1," & j & "]").text = Cells(i, 1)
  49. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3," & j & "]").text = Cells(i, 2)
  50. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3," & j & "]").setFocus
  51. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3," & j & "]").caretPosition = 19
  52. session.findById("wnd[0]").sendVKey 0
  53. session.findById("wnd[0]/tbar[1]/btn[18]").press
  54. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-POSNR[0," & j & "]").setFocus
  55. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-POSNR[0," & j & "]").caretPosition = 4
  56. session.findById("wnd[0]").sendVKey 2
  57. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09").select
  58. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").text = Cells(i, 3)
  59. session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").setSelectionIndexes 3, 3
  60. session.findById("wnd[0]/tbar[0]/btn[3]").press
  61. Next
  62. session.findById("wnd[0]/tbar[0]/btn[11]").press
  63. Cells(5, 1) = session.findById("wnd[0]/sbar").text
  64. End Sub

 然后再excel里面执行一下 

以上是测试

实际在Excel里面 开发工具→插入按钮  修改按钮名称  右键按钮 → 指定宏 为上述的runva01()

然后就可以执行了

完整的执行过程 GO 

文件

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/323790
推荐阅读
相关标签
  

闽ICP备14008679号