As the title suggests I cannot get the advanced search complete event to fire. I am running VBA through Excel 2013. I have a sub running in worksheet1 which creates a test object which then runs an advanced search. This is all working fine, and the search object does return results. However, the advanced search complete event never fires. Any ideas?
Thanks!
Main code:
Sub testing()
Dim test As Class1
Set test = New Class1
Call test.TestAdvancedSearchComplete
End Sub
Class 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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…