SAP GUI脚本循环显示警告消息



下面是用于删除源列表中特定行的SAP脚本。输入材料编号和工厂后,可能会出现警告信息(待定,需要豁免(-要继续下一步,需要输入session.findById("wnd[0]").sendVKey 0一次、两次甚至三次。同样,它取决于材料上警告信息的数量。

在下面的例子中,我使用了Enter 3次,但我希望它更动态,而不是默认使用Enter 3次。如果或只要有警告消息,它就应该计数使用Enter else移动到脚本中的下一步。

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

Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,"Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 to objSheet.UsedRange.Rows.Count
If IsEmpty(objSheet.Cells(i, 4)) Then
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nme01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtEORD-MATNR").text = COL1 'Material number
session.findById("wnd[0]/usr/ctxtEORD-WERKS").text = COL2 'Plant

session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/tblSAPLMEORTC_0205").getAbsoluteRow(COL3-1).selected = true 'Row to delete in SL
session.findById("wnd[0]/usr/tblSAPLMEORTC_0205/ctxtEORD-VDATU[0,6]").setFocus
session.findById("wnd[0]/usr/tblSAPLMEORTC_0205/ctxtEORD-VDATU[0,6]").caretPosition = 0
session.findById("wnd[0]/tbar[1]/btn[14]").press
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
session.findById("wnd[0]/tbar[0]/btn[11]").press

objSheet.Cells(i, 4) = "Deleted"

aux=COL1 & " " & COL2 & " " & COL3
CreateObject("WScript.Shell").run("cmd /c @echo %date% %time% " & aux & " >> C:SCRIPTPlOrCreationLog.txt")
End If
next
msgbox "Process Completed"

试试这个代码

Do While session.findById("wnd[0]/sbar").messageType = "W"        
session.findById("wnd[0]").sendVKey 0 
Loop

完整的代码可能看起来像这个

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


Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,"Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet

For i = 2 to objSheet.UsedRange.Rows.Count
If IsEmpty(objSheet.Cells(i, 4)) Then
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3


session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nme01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtEORD-MATNR").text = COL1 'Material number
session.findById("wnd[0]/usr/ctxtEORD-WERKS").text = COL2 'Plant


session.findById("wnd[0]").sendVKey 0    ' <= You need to press Enter at least once before you check for a warning in the statu bar
Do While session.findById("wnd[0]/sbar").messageType = "W"        
session.findById("wnd[0]").sendVKey 0 
Loop


session.findById("wnd[0]/usr/tblSAPLMEORTC_0205").getAbsoluteRow(COL3-1).selected = true 'Row to delete in SL
session.findById("wnd[0]/usr/tblSAPLMEORTC_0205/ctxtEORD-VDATU[0,6]").setFocus
session.findById("wnd[0]/usr/tblSAPLMEORTC_0205/ctxtEORD-VDATU[0,6]").caretPosition = 0
session.findById("wnd[0]/tbar[1]/btn[14]").press
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
session.findById("wnd[0]/tbar[0]/btn[11]").press


objSheet.Cells(i, 4) = "Deleted"


aux=COL1 & " " & COL2 & " " & COL3
CreateObject("WScript.Shell").run("cmd /c @echo %date% %time% " & aux & " >> C:SCRIPTPlOrCreationLog.txt")

End If
next

msgbox "Process Completed"

相关内容

  • 没有找到相关文章

最新更新