正如标题所示,我无法触发高级搜索完成事件。我正在通过Excel 2013运行VBA。我在工作表1中运行了一个子程序,它创建了一个测试对象,然后运行高级搜索。这一切都正常,搜索对象确实返回结果。但是,高级搜索完成事件永远不会触发。有什么想法吗?
谢谢!
主要代码:
Sub testing()
Dim test As Class1
Set test = New Class1
Call test.TestAdvancedSearchComplete
End Sub
第1课:
Dim myOlApp As New Outlook.Application
Public blnSearchComp As Boolean
Dim sch As Outlook.search
Dim rsts As Outlook.Results
Private Sub myOlApp_AdvancedSearchComplete(ByVal SearchObject As search)
MsgBox "The AdvancedSearchComplete Event fired."
blnSearchComp = True
End Sub
Sub TestAdvancedSearchComplete()
Dim i As Integer
blnSearchComp = False
Const strF As String = "urn:schemas:mailheader:subject = 'Test'"
Const strS As String = "Inbox"
Set sch = myOlApp.AdvancedSearch(strS, strF, False, “Test”)
While blnSearchComp = False
DoEvents
Wend
Set rsts = sch.Results
For i = 1 To rsts.Count
Debug.Print rsts.Item(i).SenderName
Next
End Sub
答案 0 :(得分:0)
AdvancedSearchComplete事件有一个特殊的过程名称,编译器需要查看该名称才能将代码绑定到事件。将过程名称更改为:
Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)
答案 1 :(得分:0)
要允许举起活动,您需要使用WithEvents
Dim WithEvents myOlApp As New Outlook.Application