vba advancedsearch, stepping the through works, running does not

Joined
May 3, 2012
Messages
1
Reaction score
0
the code below is an advancedsearch for outlook. i only have one email that fits the search term "test 2". if the code works, the number of items found is assigned to b. when i run the code sometimes it finds it other times it does not. however, when i step through, the code always works (finds the email item) ..... Any ideas ?


Sub advancedsearch1()
Dim search As Outlook.search
Dim results As Outlook.results
Dim b As Integer

'start coding
Set search = AdvancedSearch("inbox", "urn:schemas:mailheader:subject = 'test 2'")
Set results = search.results
b = results.Count
Debug.Print b

Set search = Nothing
Set results = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top