So I have a macro that updates prices in SAP GUI. It copies cell by cell and does the update order by order, but some times, right after performing the update and saving the order to go with the next line, a prompt appears in SAP where I need to click Yes or No, or Accept / Reject.
My macro then stops as it does not have a line of code to act on it. I do know which line is required, but my question is how to I write a line of code which would be executed if the prompt appears?
Keep in mind that sometimes it pops up and sometimes it does not.
Here is my code:
Public sessioninfo As SAPFEWSELib.GuiSessionInfo
Public Sub fastPFI()
Dim ws As Worksheet
Dim App As SAPFEWSELib.GuiApplication
Dim sor As Long
Dim maxsor As String
'HOEEUBV2 (EUB with scripting)
Set GuiAuto = GetObject("SAPGUI") 'Get the SAP GUI Scripting object
Set App = GuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
Set Con = App.Children(0) 'Get the first system that is currently connected
Set session = Con.Children(0) 'Get the first session (window) on that connection
Set sessioninfo = session.Info
Set ws = Excel.ThisWorkbook.Worksheets("system")
sor = 2
maxsor = ws.Cells(Rows.Count, 1).End(xlUp).Row
'maxsor = 3
Do While sor < maxsor + 1
session.StartTransaction "va02"
'session.FindById("wnd[0]").SendVKey 0
session.FindById("wnd[0]/usr/ctxtVBAK-VBELN").Text = Cells(sor, 1)
session.FindById("wnd[0]").SendVKey 0
session.FindById("wnd[1]").SendVKey 0
session.FindById("wnd[0]").SendVKey 30
session.FindById("wnd[0]").SendVKey 11
session.FindById("wnd[0]/usr/lblRV45S-BSTNK").SetFocus
session.FindById("wnd[0]/usr/lblRV45S-BSTNK").CaretPosition = 18
'session.FindById("wnd[0]").SendVKey 0
sor = sor + 1
Loop
MsgBox "All proformas have been created" & vbNewLine & "Click OK to close file"
' Application.DisplayAlerts = False
'ActiveWorkbook.Close Savechanges:=False
'Application.DisplayAlerts = True
End Sub```