0

I would have liked to have automated several extraction except that when I run the macro I have pop-up windows that annoy me terribly I can make them disappear by pressing enter.

  Public Sub RunGUIScript()

 Dim W_Ret As Boolean
 Dim Société As String
 Sheets("Extraction").Select
 Société = Range("b9")


   Application.SendKeys "{Enter}" 

 ' Connect to SAP
  W_Ret = Attach_Session
  If Not W_Ret Then
  Exit Sub
   End If


    On Error GoTo myerr



  objSess.findById("wnd[0]").maximize
  objSess.findById("wnd[0]/tbar[0]/okcd").Text = "S_ALR_87012039"
  objSess.findById("wnd[0]/tbar[0]/btn[0]").press
  objSess.findById("wnd[0]/usr/radSUMMB").Select
  objSess.findById("wnd[0]/usr/chkP_GRID").Selected = True
  [...]

  Exit Sub

  myerr:
  MsgBox "Error occured while retrieving data", vbCritical + vbOKOnly


  End Sub

The "Application.SendKeys "{Enter}" feature does not make my SAP windows disappear so it is not the solution that works

Windows popup A script attempts connecting to SAP GUI

SAP popup No data was selected

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
dfiu
  • 5
  • 1
  • 5

1 Answers1

1

The first popup is SAP telling you, that a script is trying to access SAP. You can disable that information in the SAP settings.
Go to Options -> Accessibility & Scripting -> Scripting
And then remove the checkmark from "Notify when a script attaches to SAP GUI" and "Notify when a script opens a connection"

enter image description here

The second popup can be closed with this line:

objSess.FindById("wnd[1]/tbar[0]/btn[0]").Press

This will press the Ok button in the popup.

And if you want to know if the window did popup you can do that like this:

On Error Resume Next
objSess.FindById("wnd[1]/tbar[0]/btn[0]").Press
If Err.Number = 0 Then
    'Button was pressed
End If
On Error GoTo 0

Put this piece of code after the line of code that causes the window to popup.

Nacorid
  • 783
  • 8
  • 21