How to handle intermittent pop-up window

The goal of this macro is to add the correct value of the carriage in the Billing Notes of each one of the orders from a column of the input Excel file.

The expected result is a smooth run. The actual result is that the script runs fine up until it works on an order which shows the pop up window Not Optimized container after saving changes. Run-time error 619: The control could not be found by id is the error message.

This is the pop up that may or may not appear

This script is looped. Based on the location of the error, I assume the script is trying to run the loop again, but as this pop-up window is in the middle of the screen it can't advance.

I have tried Errhandler, On Error GoTo, On Error Resume Next in the final line of the code before Range ("E" & i) = "uploaded" but the script will always stop on the line when the pop-up does not appear.

Here is my code, in bold the lines I believe would solve the pop-up issue. I do not know, nor can I apply a strategy, that would allow the macro to ignore this line if the pop-up does not appear.

So, in short, how do I make the script ignore this line if the no optimized container does not show, and execute the click on Yes if it does?

I have checked https://answers.sap.com/questions/3285089/check-for-popup-within-script.html.

'step 2 - VA02

Dim concat As String
concat = Range("D2")
Dim cell As String
Dim i As String

i = 2
cell = Range("B" & i)
concat = Range("D" & i)

session.FindById("wnd[0]").maximize
session.FindById("wnd[0]/tbar[0]/btn[15]").press
session.FindById("wnd[0]/tbar[0]/btn[15]").press
session.FindById("wnd[0]/tbar[0]/okcd").Text = "VA02"
session.FindById("wnd[0]").sendVKey 0

Do While cell <> ""
cell = Range("B" & i)
concat = Range("D" & i)

session.FindById("wnd[0]/usr/ctxtVBAK-VBELN").Text = cell
session.FindById("wnd[0]").sendVKey 0
session.FindById("wnd[0]").sendVKey 0
**'session.findById("wnd[1]/tbar[0]/btn[0]").press**
session.FindById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/btnBT_HEAD").press
session.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10").Select
session.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[0]/shell").selectItem "ZZ05", "Column1"
session.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[0]/shell").ensureVisibleHorizontalItem "ZZ05", "Column1"
session.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[0]/shell").doubleClickItem "ZZ05", "Column1"
session.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").setSelectionIndexes 0, 100
session.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/btnTP_DELETE").press
session.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").Text = concat
session.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").setSelectionIndexes 47, 47
session.FindById("wnd[0]/tbar[0]/btn[11]").press
**'session.findById("wnd[1]/usr/btnZSPOP_PRIMARY-OPTION1").press**

Range("E" & i) = "uploaded"

i = i + 1
    
Loop

MsgBox ("Done")
    
End Sub

Upvotes: 0

Views: 1236

Answers (1)

BrunoQuintero
BrunoQuintero

Reputation: 151

This will check if the pop up appears or not.

If session.ActiveWindow.Name = "wnd[1]" Then
    session.findById("wnd[1]/usr/btnZSPOP_PRIMARY-OPTION1").press
End If

Upvotes: 1

Related Questions