excel - 如何处理等待另一个应用程序 (SAP GUI) 完成 OLE 操作的情况?

标签 excel vba sap-gui

我正在尝试在 SAP GUI 中实现流程自动化。

我录制了一系列程序并将代码粘贴到宏表中。我使用以下命令让 Excel 读取 VBA 代码:

Dim SapGuiAuto As Object
Dim Application As Object
Dim Connection As Object
Dim Session As Object

Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
Set Connection = Application.Children(0)
Set Session = Connection.Children(0)

对于 SAP 进行大量计算的其中一个部分,这需要几分钟的时间,在中间,Excel 会生成消息:
enter image description here

我必须单击“确定”才能继续,然后它会不停地弹出,我必须执行 10-15 次,这消除了自动化点。

在没有宏的情况下执行此操作时,SAP 不会给我任何错误。

我尝试将其关闭

Application.DisplayAlerts = False

它给了我:

enter image description here

我搜索了网络和网站,但几乎没有任何有用的信息,也许是因为我的问题太具体了。

一些附加信息:

  1. 我的笔记本电脑正在工作,未经许可我无法安装任何其他软件或更新。
  2. 我尝试检查 DDE 的 Excel 选项,但当我尝试运行脚本时它只会给出错误。
    enter image description here

我的 Excel 版本是 2013。

如何实现我能想到的三种解决方案之一:

  1. 禁用 OLE 弹出窗口
  2. 使其每次出现时自动单击“确定”
  3. 让 Excel 卡住并等待 SAP 执行其操作? (不知道这是否有意义。)尝试使用 Application.Wait,但没有成功

最佳答案

上面的Storax实际上给出了另一个主题的链接以及问题的解决方案。

代码在这里:

Private Declare Function _
    CoRegisterMessageFilter Lib "OLE32.DLL" _
    (ByVal lFilterIn As Long, _
    ByRef lPreviousFilter) As Long

Sub KillMessageFilter()  
    '''Original script Rob Bovey  

    '''https://groups.google.com/forum/?hl=en#!msg/microsoft.public.excel.programming/ct8NRT-o7rs/jawi42S8Ci0J
    '''http://www.appspro.com/

    Dim lMsgFilter As Long

    ''' Remove the message filter before calling Reflections.
    CoRegisterMessageFilter 0&, lMsgFilter

    ''' Call your code here....

    ''' Restore the message filter after calling Reflections.
    CoRegisterMessageFilter lMsgFilter, lMsgFilter

End Sub

关于excel - 如何处理等待另一个应用程序 (SAP GUI) 完成 OLE 操作的情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50142068/

相关文章:

excel - 如何在 Excel 中生成具有已知初始值和最终值的指数系列值

excel - 查找列中重复条目的行

performance - 从工作表中删除命令按钮和行非常慢

Excel VBA 宏 - 复制并插入复制的单元格

excel - Excel 中按轮廓级别(组)着色

sap-gui - SapTable 中已填充的行数

excel - 使用 vlookup 或索引/匹配函数对多行中的值求和

excel - 使用 VBA 宏取消选择 Excel 工作簿中的所有复选框

excel - 在 Excel VBA 中禁用 SAP 登录弹出窗口

excel - 通过 Excel VBA 在 Citrix 上连接 SAP