Skip to Content

vba code only returns value for the first time when sap gui scripting doesn't find a value

hello,

I'm new to vba and sap gui scripting, if you can help me to get this solved I will really appreciate it.

I think I have a problem with the error handling statement maybe. it supposed to put the icon value(Green per example) in column C if there is any and to leave column C empty and put "No icon " on column B and then go to the next cell and check again if there is an icon or now.

I have a list of element in excel (Column A) that I want to check in sap and instead of checking one by one manually I'm working on a macro to check all the items on excel and returns the value of the icon (if green in sap, it should return the icon value and put it on column "C") if it doesn't find the icon it should put the value : no icon found on column "B".

I tried to put on error resume next but the problem is that it only work once and then it start puting the same value in column C and B regardless if there is a green icon or not.

if I don't put in error handling method, once there is no icon, vba shows that the problem is on the below line:

session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3").Columns.elementAt(0).Width = 4

but when I do the following it works properly (puts "no icon" )and end exit the macro:

'=====================Column A contains the Numbers I want to check on sap

on error goto msg

For Each rng In Columns("A").Cells.SpecialCells(xlCellTypeConstants)
Elements= Cells(Elem.Row, "A").Value
If Elem.Value Like "?56*" Then

'============================================

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nvf03"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtVBRK-VBELN").Text = Elements
session.findById("wnd[0]/usr/ctxtVBRK-VBELN").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/mbar/menu[2]/menu[0]/menu[3]").Select
session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3").Columns.elementAt(0).Width = 4
session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/lblDV70A-STATUSICON[0,1]").SetFocus
session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/lblDV70A-STATUSICON[0,1]").caretPosition = 0
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3").Columns.elementAt(0).Width = 4
session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/lblDV70A-STATUSICON[0,1]").SetFocus
session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/lblDV70A-STATUSICON[0,1]").caretPosition = 0
Value = session.findById("wnd[0]/usr/tblSAPDV70ATC_NAST3/lblDV70A-STATUSICON[0,1]").IconName
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press

Cells(rng.Row, "C") = value

End If
Next

msg:

cells(rng.row, "D").value = "No icon"
End Sub

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Oct 23, 2019 at 05:27 AM

    Hi,

    You probably have several names like me but always the same problem.

    If so, you can look here:

    https://stackoverflow.com/questions/58471022/vba-sap-scripting-if-no-icon-found/58501656#58501656

    Regards, ScriptMan

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.