如果您想阻止任何消息出现(例如,如果您已将光标更改为沙漏),那么您想使用App.OleRequestPendingTimeout
而不是App.OleServerBusyTimeout
.
或者,您还可以使用设置备用消息App.OLERequestPendingMsgText
。这样做只会通过一个 OK 按钮向用户显示您的自定义消息 - 这不会令人困惑。
这是一些示例代码:
' set up special message if user interacts with application while waiting on the
' long-running operation to complete
' see http://support.microsoft.com/kb/138066
Dim originalOLEPendingMessage As String
originalOLEPendingMessage = App.OleRequestPendingMsgText
App.OleRequestPendingMsgText = "Please be patient while your request is processed."
Dim originalOLEPendingTimeout as Long
originalOLEPendingTimeout = App.OleRequestPendingTimeout
App.OleRequestPendingTimeout = 10000
On Error GoTo Finally
' Call long-running process here
Finally:
' If an actual error occurred we want to capture all the properties of Err
' so we can re-raise it after we clean up
Dim errNumber As Long
Dim ERRSOURCE As String
Dim errDesc As String
Dim errHelpFile As String
Dim errHelpContext As Long
errNumber = Err.Number
ERRSOURCE = Err.Source
errDesc = Err.Description
errHelpFile = Err.HelpFile
errHelpContext = Err.HelpContext
App.OleRequestPendingMsgText = originalOLEPendingMessage
App.OleRequestPendingTimeout = originalOLEPendingTimeout
If errNumber <> 0 Then
Err.Raise errNumber, ERRSOURCE, errDesc, errHelpFile, errHelpContext
End If
有关详细讨论,请参阅 Microsoft 知识库文章如何处理 OLE 自动化服务器超时和同步。