我尝试运行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 = "CS03"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRC29N-STLAN").setFocus
session.findById("wnd[0]/usr/ctxtRC29N-STLAN").caretPosition = 0
session.findById("wnd[0]").sendVKey 4
session.findById("wnd[1]/usr/lbl[1,10]").setFocus
session.findById("wnd[1]/usr/lbl[1,10]").caretPosition = 0
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/ctxtRC29N-MATNR").text = "508546"
session.findById("wnd[0]/usr/ctxtRC29N-WERKS").text = "1000"
session.findById("wnd[0]/usr/ctxtRC29N-WERKS").setFocus
session.findById("wnd[0]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/tblSAPLCSDITCALT/ctxtRC29K-STLST[1,15]").setFocus
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/usr/tblSAPLCSDITCALT/ctxtRC29K-STLST[1,15]").setFocus
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tabsTS_ITOV/tabpTCDO").select
session.findById("wnd[0]/usr/tabsTS_ITOV/tabpTCMA").select
session.findById("wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-KTEXT[3,3]").setFocus
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tabsTS_ITEM/tabpPDAT").select
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/txtRC29P-KTEXT[3,6]").setFocus
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tabsTS_ITEM/tabpPDAT/ssubSUBPAGE:SAPLCSDI:0840/btnRC29P-ICON1").press
session.findById("wnd[0]/usr/cntlSCMSW_CONTAINER_2102/shellcont/shell").setDocument 1,"e1xydGYxXGFkZWZsYW5nMTAyNVxhbnNpXGFuc2ljcGcxMjUyXHVjM="
显然,我没有得到所需的结果,因为我想要检索显示的文本而不是文本字段。关于如何获得的任何想法?
答案 0 :(得分:1)
首先,尝试使用.setFocus
方法代替.Text
方法。然后创建像strMyText
这样的变量。之后,将SAP中的文本分配给此变量,最后将其粘贴到某处。
所以它会是这样的:
Sub SAPText()
Dim strMyText
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 = "CS03"
session.findById("wnd[0]").sendVKey 0
strMyText = session.findById("wnd[0]/usr/ctxtRC29N-STLAN").Text
Activecell.value = strMyText
End sub