【发布时间】:2018-12-13 22:24:14
【问题描述】:
我有一个 Excel VBA 代码可以从 SAP 下载一些数据,它工作正常。 但在流程中有一个特定点,SAP 可以显示警告消息:“警告:系统响应时间”、“选择了大量行项目 [...]”。它不会出现在所有代码运行中。 问题是 - 我如何测试此消息是否能够在 Excel VBA 中使用 if/else?
【问题讨论】:
我有一个 Excel VBA 代码可以从 SAP 下载一些数据,它工作正常。 但在流程中有一个特定点,SAP 可以显示警告消息:“警告:系统响应时间”、“选择了大量行项目 [...]”。它不会出现在所有代码运行中。 问题是 - 我如何测试此消息是否能够在 Excel VBA 中使用 if/else?
【问题讨论】:
我为此创建了一个类,并且在我拥有的类中
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 会话的链接
【讨论】: