-2

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```
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 2
    What exactly do you mean by "in SAP"? What is "SAP" in your context? SAP is a company. Please specify which products or tech stack you're using. This [community wiki](https://meta.stackoverflow.com/a/404098) might help to choose better tags. – Boghyon Hoffmann Jan 11 '21 at 14:24
  • 1
    Have you seen the following question in the SAP dev network? https://answers.sap.com/questions/3285089/check-for-popup-within-script.html – Marc Jan 12 '21 at 07:57

1 Answers1

-2

On Error GoTo Next after the line of code which could or not happen solved it.

June7
  • 19,874
  • 8
  • 24
  • 34