【发布时间】:2021-05-24 13:47:22
【问题描述】:
我在 Outlook 中编写了 VBA 代码以使用 AdvancedSearch。它奏效了。
当我将它移至 Excel 以成为更大例程的一部分时,事件处理程序停止工作。
主代码如下所示。
Public gblnProcessAttachmentsDone As Boolean
Public gblnProcessAttachmentsStopped As Boolean
Sub ProcessAttachmentsSub()
' this routine performs the advanced search on a folder
...
gblnProcessAttachmentsDone = False
gblnProcessAttachmentsStopped = False
...
'perform search
Set objSearch = objOL.AdvancedSearch(strScope, strFilter, True, "ProcessAttachments")
Do Until gblnProcessAttachmentsDone
DoEvents
Loop
这些是事件处理程序。
Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Outlook.Search)
' this routine identifies the search that has just completed
If SearchObject.Tag = "ProcessAttachments" Then
Debug.Print "Search completed at " & Time
gblnProcessAttachmentsDone = True
End If
End Sub
Private Sub Application_AdvancedSearchStopped(ByVal SearchObject As Outlook.Search)
' this routine identifies the search that has just been stopped by the user
If SearchObject.Tag = "ProcessAttachments" Then
Debug.Print "Search stopped at " & Time
gblnProcessAttachmentsStopped = True
gblnProcessAttachmentsDone = True
End If
End Sub
我尝试将它们放在“ThisWorkbook”和 Class 模块中,但在这两种情况下,事件都不会被捕获。
【问题讨论】:
-
我已经编辑了您的问题,在您的源代码前后添加了一些反引号(或重音符号),如此 URL 所示:stackoverflow.com/help/formatting,它使您的源代码更具可读性。跨度>
-
谢谢你——我的第一篇文章。我尝试格式化文本,但失败了!我今天会检查那个格式链接!