赞
踩
首先要开启SAP的脚本 参考 SAP系统开启脚本录制和回放功能 - 简书
参考一边生成销售订单的过程 注意不要有额外的操作 记录下脚本
- If Not IsObject(application) Then
- Set SapGuiAuto = GetObject("SAPGUI")
- Set application = SapGuiAuto.GetScriptingEngine
- End If
- If Not IsObject(connection) Then
- Set connection = application.Children(0)
- End If
- If Not IsObject(session) Then
- Set session = connection.Children(0)
- End If
- If IsObject(WScript) Then
- WScript.ConnectObject session, "on"
- WScript.ConnectObject application, "on"
- End If
- session.findById("wnd[0]").maximize
- session.findById("wnd[0]/tbar[0]/okcd").text = "va01"
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]/usr/ctxtVBAK-AUART").text = "ZTA"
- session.findById("wnd[0]/usr/ctxtVBAK-VKORG").text = "1000"
- session.findById("wnd[0]/usr/ctxtVBAK-VTWEG").text = "20"
- session.findById("wnd[0]/usr/ctxtVBAK-SPART").text = "00"
- session.findById("wnd[0]/usr/ctxtVBAK-SPART").setFocus
- session.findById("wnd[0]/usr/ctxtVBAK-SPART").caretPosition = 2
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").text = "1 1"
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:SAPMV45A:4701/ctxtKUAGV-KUNNR").text = "100002"
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:SAPMV45A:4701/ctxtKUWEV-KUNNR").text = "100002"
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").setFocus
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").caretPosition = 3
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/btnBT_HEAD").press
- session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09").select
- 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 + ""
- 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
- session.findById("wnd[0]/tbar[0]/btn[3]").press
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/ctxtVBKD-BSTDK").text = "20211201"
- 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"
- 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"
- 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
- 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
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]/tbar[1]/btn[18]").press
- 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
- 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
- session.findById("wnd[0]").sendVKey 2
- session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09").select
- 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 + ""
- 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
- session.findById("wnd[0]/tbar[0]/btn[3]").press
- 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"
- 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"
- 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
- 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
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]/tbar[1]/btn[18]").press
- 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
- 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
- session.findById("wnd[0]").sendVKey 2
- 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 + ""
- 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
- session.findById("wnd[0]/tbar[0]/btn[11]").press
-
- Cells(5, 1) = session.findById("wnd[0]/sbar").text
新建一个excel 进入开发工具,把上面的脚本拖入到里面 ,
加入Sub runva01()
末尾加入 end sub
编辑Excel表格
注意:表格的内容是指你要输入SAP 销售订单 的内容
修改一下脚本如下:
- Sub runva01()
- Dim i, j, itemi, itemj, randx, strp, modvalue
- itemi = Cells(1, 3)
- itemj = Cells(1, 5)
-
- modvalue = Cells(4, 9)
-
- If Not IsObject(sapapplication) Then
- Set SapGuiAuto = GetObject("SAPGUI")
- Set sapapplication = SapGuiAuto.GetScriptingEngine
- End If
- If Not IsObject(connection) Then
- Set connection = sapapplication.Children(0)
- End If
- If Not IsObject(session) Then
- Set session = connection.Children(0)
- End If
- If IsObject(WScript) Then
- WScript.ConnectObject session, "on"
- WScript.ConnectObject sapapplication, "on"
- End If
- session.findById("wnd[0]").maximize
- session.findById("wnd[0]/tbar[0]/okcd").text = "va01"
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]/usr/ctxtVBAK-AUART").text = "ZTA"
- session.findById("wnd[0]/usr/ctxtVBAK-VKORG").text = "1000"
- session.findById("wnd[0]/usr/ctxtVBAK-VTWEG").text = "20"
- session.findById("wnd[0]/usr/ctxtVBAK-SPART").text = "00"
- session.findById("wnd[0]/usr/ctxtVBAK-SPART").setFocus
- session.findById("wnd[0]/usr/ctxtVBAK-SPART").caretPosition = 2
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").text = Cells(4, 4)
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:SAPMV45A:4701/ctxtKUAGV-KUNNR").text = Cells(4, 6)
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:SAPMV45A:4701/ctxtKUWEV-KUNNR").text = Cells(4, 7)
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").setFocus
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").caretPosition = 3
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/btnBT_HEAD").press
- session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09").select
- 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)
- 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
- session.findById("wnd[0]/tbar[0]/btn[3]").press
- session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/ctxtVBKD-BSTDK").text = Cells(4, 5)
-
- For i = itemi To itemj
- j = i - itemi
- While j >= modvalue
- j = j - modvalue + 1
- Wend
-
- 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)
- 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)
- 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
- 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
- session.findById("wnd[0]").sendVKey 0
- session.findById("wnd[0]/tbar[1]/btn[18]").press
- 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
- 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
- session.findById("wnd[0]").sendVKey 2
- session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\09").select
- 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)
- 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
- session.findById("wnd[0]/tbar[0]/btn[3]").press
-
- Next
-
- session.findById("wnd[0]/tbar[0]/btn[11]").press
-
- Cells(5, 1) = session.findById("wnd[0]/sbar").text
- End Sub
然后再excel里面执行一下
以上是测试
实际在Excel里面 开发工具→插入按钮 修改按钮名称 右键按钮 → 指定宏 为上述的runva01()
然后就可以执行了
完整的执行过程 GO
文件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。