0
votes

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
Can you share a screenshot of what "aborts in SAP"? Your code fails on my system, can you post a complete, minimal and reproducible code? I don't understand if your issue comes from Excel or from SAP GUI Scripting, can you isolate the source of the issue?Sandra Rossi

1 Answers

1
votes

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