Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

To allow raising events you need to declare your objects with WithEvents

Dim WithEvents myOlApp As New Outlook.Application

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...