cancel
Showing results for 
Search instead for 
Did you mean: 

Help with a Loop Pop up VBA

Former Member
0 Kudos

Hello Everybody,

I am new to the SAP community and also to the script world, I need your help with a peace of script that I am developing for sales operations, the script will do copy information from excel and pasted into SAP, the problem I am having is with a loop for the pop up messages it will go infinitive; I can´t think of a way to stop it.

thank you.

If Not IsObject(app) Then

   Set SapGuiAuto = GetObject("SAPGUI")

   Set app = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

   Set connection = app.Children(0)

End If

If Not IsObject(session) Then

   Set session = connection.Children(0)

End If

If IsObject(WScript) Then

   WScript.ConnectObject session, "on"

   WScript.ConnectObject app, "on"

  

End If

Do Until Not session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\02")

Debug.Print "a level 1 popup screen appeared with the name ", session.findById("wnd[1]").Text

If Not session.findById("wnd[1]/usr/btnSPOP-VAROPTION1", False) Is Nothing Then

session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press

End If

On Error Resume Next

If Not session.findById("wnd[1]/tbar[0]/btn[0]", False) Is Nothing Then

session.findById("wnd[1]/tbar[0]/btn[0]").press

End If

If Not session.findById("wnd[0]", False) Is Nothing Then

session.findById("wnd[0]").sendVKey 3

End If

If Not session.findById("wnd[0]", False) Is Nothing Then

session.findById("wnd[0]").sendVKey 6

End If

If Not session.findById("wnd[0]", False) Is Nothing Then

session.findById("wnd[0]").sendVKey 2

End If

If Not session.findById("wnd[0]/shellcont/shell/shellcont[0]/shell", False) Is Nothing Then

session.findById("wnd[0]/shellcont/shell/shellcont[0]/shell").pressbutton "CONT"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\03").select

End If

Loop

c = ThisWorkbook.Sheets("1").Range("B6").Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\03/ssubSUBSCREEN_BODY:SAPMV45A:4303/ctxtVBAK-TAXK1").Text = c

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\03/ssubSUBSCREEN_BODY:SAPMV45A:4303/ctxtVBAK-LANDTX").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\03/ssubSUBSCREEN_BODY:SAPMV45A:4303/ctxtVBAK-LANDTX").caretPosition = 0

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

End Sub

Accepted Solutions (1)

Accepted Solutions (1)

script_man
Active Contributor
0 Kudos

Hi Luis,

You can try the following:

. . .

Do Until Not session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\02")

on error resume next

session.findById("wnd[1]") .close

on error goto 0

If Not session.findById("wnd[0]", False) Is Nothing Then

session.findById("wnd[0]").sendVKey 3

End If

If Not session.findById("wnd[0]", False) Is Nothing Then

session.findById("wnd[0]").sendVKey 6

End If

If Not session.findById("wnd[0]", False) Is Nothing Then

session.findById("wnd[0]").sendVKey 2

End If

If Not session.findById("wnd[0]/shellcont/shell/shellcont[0]/shell", False) Is Nothing Then

session.findById("wnd[0]/shellcont/shell/shellcont[0]/shell").pressbutton "CONT"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\03").select

End If

Loop

. . .

Regards,

ScriptMan

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Scriptman,

Sorry for the delay, I was on Vacations, I try it and I still got some issues, so I try the following and it seems to work:

Do While session.ActiveWindow.Name = "wnd[1]"

Debug.Print "a level 1 popup screen appeared with the name ", session.findById("wnd[1]").Text

If Not session.findById("wnd[1]/usr/btnSPOP-VAROPTION1", False) Is Nothing Then

session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press

End If

On Error Resume Next

If Not session.findById("wnd[1]/tbar[0]/btn[0]", False) Is Nothing Then

session.findById("wnd[1]/tbar[0]/btn[0]").press

End If

    If session.findById("wnd[0]").Text = "Trade order: Availability Control" Then

    session.findById("wnd[0]").sendVKey 6

    End If

    If session.findById.Left("wnd[0]", [22]).Text = "APO Availability Check" Then

    session.findById("wnd[0]/shellcont/shell/shellcont[0]/shell").pressbutton "CONT"

    End If

    If Not session.findById("wnd[0]", False) Is Nothing Then

    session.findById("wnd[0]").sendVKey 2

    End If

Loop

End If