How to close SAP pop-up windows with VBA?

我只是一个虾纸丫 提交于 2020-12-15 07:08:31

问题


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


回答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"

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.



来源:https://stackoverflow.com/questions/56749438/how-to-close-sap-pop-up-windows-with-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!