【问题标题】:VBA code to test if a warning in SAP appeared用于测试 SAP 中是否出现警告的 VBA 代码
【发布时间】:2018-12-13 22:24:14
【问题描述】:

我有一个 Excel VBA 代码可以从 SAP 下载一些数据,它工作正常。 但在流程中有一个特定点,SAP 可以显示警告消息:“警告:系统响应时间”、“选择了大量行项目 [...]”。它不会出现在所有代码运行中。 问题是 - 我如何测试此消息是否能够在 Excel VBA 中使用 if/else?

【问题讨论】:

    标签: excel sap warnings vba


    【解决方案1】:

    我为此创建了一个类,并且在我拥有的类中

    Function StatusBarWarning() As Boolean
    
    Dim objSapStatusBar As Object
    
        On Error GoTo ErrSapStatusBarWarning
        StatusBarWarning = True
    
        Set objSapStatusBar = mSapSes.findById("wnd[0]/sbar")
        If objSapStatusBar.messagetype = "W" Then
            StatusBarWarning = True
        Else
            StatusBarWarning = False
        End If
    
        Exit Function
    
    ErrSapStatusBarWarning:
        StatusBarWarning = True
    
    End Function
    

    mSapSes 是 SapGui 会话的链接

    【讨论】:

    • 与此同时,我尝试了类似'If Session.ActiveWindow.Text = "Warning: System answer time" Then Session.FindById("wnd[0]/usr/tabsGC_MAINTAB/tabpBLNC/ssubBODY: SAPLFDBL:0100/cntlFDBL_BALANCE_CONTAINER/shellcont/shell").DoubleClickCurrentCell Session.FindById("wnd[1]/usr/btnSPOP-VAROPTION2").Press End If' 它可以工作,但我知道会弹出什么样的警告下一步点击什么按钮。不过我会试试你的方法。
    • 无论如何,当我运行我的代码时,我会启动一个新的 SAP 会话,您是否知道如何强制新的 SAP 窗口留在后台?简单的 'Application.ScreenUpdating = False' 不起作用,无论我使用它的代码中的哪一点...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 2015-03-17
    • 2018-08-24
    • 2016-02-28
    • 1970-01-01
    相关资源
    最近更新 更多