如何使用VBA关闭SAP弹出窗口? [英] How to close SAP pop-up windows with VBA?

查看:584
本文介绍了如何使用VBA关闭SAP弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了运行宏时,我会自动弹出多个窗口,这些窗口使我非常烦恼,我可以通过按Enter键使它们消失,这本来是我想自动进行的.

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

" Application.SendKeys" {Enter}"功能不会使我的SAP窗口消失,因此它不是解决方案

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

推荐答案

第一个弹出窗口是SAP告诉您脚本正在尝试访问SAP.您可以在SAP设置中禁用该信息.
转到选项->辅助功能和功能;脚本->脚本
然后,取消选中脚本附加到SAP GUI时通知"和脚本打开连接时通知"

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.

这篇关于如何使用VBA关闭SAP弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆