XDSSIOP
XDSSIOP

Reputation: 91

How to continue running a VBA macro when an SAP GUI popup message says no data found?

When the SAP GUI script searches for data via SAP GUI and finds nothing, it sends us a pop-up message saying "that it has not found any data", how to keep the macro running because later there are other transactions.

 Sub FOS()
 ...
      
On Error GoTo ConsoleAbs
Set Sapgui = GetObject("SAPGUI")
On Error GoTo 0

'transaction1
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "S_ALR_87011964"
session.findById("wnd[0]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/ctxtBUKRS-LOW").Text = "0092"
...


'transaction2

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "S_ALR_87012039"
session.findById("wnd[0]/tbar[0]/btn[0]").press
...

End Sub

I've been trying

On Error GoTo ConsoleAbs
Set Sapgui = GetObject("SAPGUI")
On Error GoTo 0

but I'm not sure that's the right solution.

Upvotes: 0

Views: 3452

Answers (1)

ScriptMan
ScriptMan

Reputation: 1625

You could try the following.

for example:

Sub FOS()
Set SapGuiAuto = GetObject("SAPGUI")
Set SAP_Application = SapGuiAuto.GetScriptingEngine
Set Connection = SAP_Application.Children(0)
Set session = Connection.Children(0)

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nS_ALR_87011964"
session.findById("wnd[0]").sendVKey 0
...
session.findById("wnd[0]/tbar[1]/btn[8]").press
If session.ActiveWindow.Name = "wnd[1]" Then
   If session.findById("wnd[1]").Text = "Information" Then session.findById("wnd[1]/tbar[0]/btn[0]").press
else
  'do something 
end if

session.findById("wnd[0]/tbar[0]/okcd").Text = "S_ALR_87012039"
session.findById("wnd[0]/tbar[0]/btn[0]").press
...
session.findById("wnd[0]/tbar[1]/btn[8]").press
If session.ActiveWindow.Name = "wnd[1]" Then
   If session.findById("wnd[1]").Text = "Information" Then session.findById("wnd[1]/tbar[0]/btn[0]").press
else
  'do something 
end if
End Sub

Regards, ScriptMan

Upvotes: 2

Related Questions