How check if exists the field? I tried it:
If session.findById("wnd[1]").setFocus Then
How check if exists the field? I tried it:
If session.findById("wnd[1]").setFocus Then
you can try e.g. the following:
on error resume next
session.findById("wnd[1]").setfocus
if err.number = 0 then
msgbox "The SAP GUI element exists."
else
msgbox "The SAP GUI element does not exist."
end if
on error goto 0
Regards, ScriptMan
To avoid using error handling you can use:
If Not session.findById("wnd[1]", False) Is Nothing Then
session.findById("wnd[1]").setFocus
End If
The key here is the second parameter in FindById which determines if it raises an error or not if the field or any object in SAP exists. If it is set to False there is no error raised and the object is set to Nothing which you can check as in my code.
If the question is how to see if there's a second window: wnd[1]
This should work:
Sub test()
If session.Children.Count = 2 then
'your code goes here
End If
End Sub
It also has the advantage that it doesn't need to use error handling to work,
so another type of error could occur and still be handled.