How to return SAP error message in excel cell through VBA?

泄露秘密 提交于 2021-01-07 02:30:57

问题


I wrote an automation script that uses the following SAP GUI:

objSess.findById("wnd[0]").Maximize
objSess.findById("wnd[0]/tbar[0]/okcd").Text = "flqaf"
objSess.findById("wnd[0]").sendVKey 0
objSess.findById("wnd[0]").sendVKey 17
objSess.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").CurrentCellColumn = "TEXT"
objSess.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").SelectedRows = "0"
objSess.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").DoubleClickCurrentCell
objSess.findById("wnd[0]/usr/ctxtS_BELNR-LOW").Text = W_BPNumber
objSess.findById("wnd[0]/usr/ctxtS_BELNR-LOW").SetFocus
objSess.findById("wnd[0]/usr/ctxtS_BELNR-LOW").caretPosition = 10
objSess.findById("wnd[0]").sendVKey 8
objSess.findById("wnd[0]").sendVKey 0
objSess.findById("wnd[0]/tbar[0]/btn[3]").press

Everything works fine, however sometimes the problem aborts in SAP and exactly when that happens I want to capture it by writing the term "error" into an excel cell.

I tried adding this line in vba

objSheet.Cells(iRow, 5) = GuiStatusbar.Text

As well as

objSheet.Cells(iRow, 5) = objSessFindById("wnd[0]/sbar").Text 

The code still runs fine but my cells in column 5 remain empty. Any ideas how to solve this?


回答1:


It might help if you wait a little.

fo example:

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

waitTill = Now() + TimeValue("00:00:01")
While Now() < waitTill
 DoEvents
Wend

if objSess.findById("wnd[0]/sbar").messageType = "E" then 'other types: W, I, S, A
 objSheet.Cells(iRow, 5) = objSessFindById("wnd[0]/sbar").Text 
end if

objSess.findById("wnd[0]/tbar[0]/btn[3]").press
...

Regards, ScriptMan



来源:https://stackoverflow.com/questions/60166357/how-to-return-sap-error-message-in-excel-cell-through-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!