 |
|
|
|
| Author |
Message |
mad.scientist.jr
Joined: 22 Jan 2008 Posts: 4
|
Posted: Tue Jan 22, 2008 5:32 pm Post subject: searching for messages where hour(Sent) >= 6 AM and hour(Sen |
|
|
I needed to see all messages in my "Sent" folder that were sent
between 6 AM and 9 AM, so I tried
Advanced Search > Advanced tab > Define more criteria
with
Field: Sent
Condition: between
Value: 6 am and 9 am
but it was not returning anything.
A macro should be able to do it, but I have not had any luck getting
it to work (or finding a decent example that will work in OL 2003).
Can someone post a VBA macro to accomplish the above search or explain
what is wrong with the code below?
Any help would be much appreciated... thanks
'this example searches for any messages in Inbox with a subject of
"Test"
'but returns
'Run-time error '91':
'Object variable or With block variable not set
Sub TestOutlookSearch()
Dim oApp As New Outlook.Application
Dim oSearch As Outlook.Search
Dim iItem As Integer
Dim sResult As String
oSearch = oApp.AdvancedSearch("Inbox",
"urn:schemas:mailheader:subject = 'Test'", True, "") ' search string/
schema examples?
Set oResults = oSearch.Results
For iItem = 1 To oSearch.Results.Count
sResult = sResult & oSearch.Results.Item(iItem).SenderName &
vbCrLf ' what are the other Item properties?
Next
MsgBox (sResult)
End Sub
Archived from group: microsoft>public>office>developer>outlook>vba |
|
| Back to top |
|
 |
mad.scientist.jr
Joined: 22 Jan 2008 Posts: 4
|
Posted: Tue Jan 22, 2008 5:57 pm Post subject: Re: searching for messages where hour(Sent) >= 6 AM and hour |
|
|
I figured out the 'Object variable or With block variable not set'
error
(forgot a "set", duh)
however I am getting 0 results. I think either the code is in the
wrong place
(in the vb editor, I created a new module Module1, under /Project1/
Modules/ )
or one of the parameters to oApp.AdvancedSearch (maybe Filter) is not
right.
The strange thing was that while I was poking around in the object
browser earlier, the code did manage to return a result - but I have
not been able to repeat this.
'this example searches for any messages in Inbox with a subject of
"Test"
'Q: what are the other Item properties?
'A: see object browser, objects: Search, Results, MailItem
Sub TestOutlookSearch()
Dim oApp As New Outlook.Application
Dim oSearch As Outlook.Search
Dim iItem As Integer
Dim sResult As String
'returns 0 messages:
Set oSearch = oApp.AdvancedSearch("Inbox",
"urn:schemas:mailheader:subject = 'Test'", True, "")
'Set oSearch = oApp.AdvancedSearch("Inbox",
"urn:schemas:mailheader:subject LIKE '%test%'", True, "")
Set oResults = oSearch.Results
sResult = ""
sResult = sResult & "Found " & oSearch.Results.Count & "
messages." & vbCrLf
sResult = sResult & "----------" & vbCrLf
For iItem = 1 To oSearch.Results.Count
'sResult = sResult & oSearch.Results.Item(iItem).SenderName &
vbCrLf
sResult = sResult & "To:" & oSearch.Results.Item(iItem).To &
vbCrLf
sResult = sResult & "CC:" & oSearch.Results.Item(iItem).CC &
vbCrLf
sResult = sResult & "BCC:" & oSearch.Results.Item(iItem).BCC &
vbCrLf
sResult = sResult & "OutlookVersion:" &
oSearch.Results.Item(iItem).OutlookVersion & vbCrLf
sResult = sResult & "CreationTime:" &
oSearch.Results.Item(iItem).CreationTime & vbCrLf
sResult = sResult & "Sent:" & oSearch.Results.Item(iItem).Sent
& vbCrLf
sResult = sResult & "Subject:" &
oSearch.Results.Item(iItem).Subject & vbCrLf
sResult = sResult & "Body:" & oSearch.Results.Item(iItem).Body
& vbCrLf
sResult = sResult & "HTMLBody:" &
oSearch.Results.Item(iItem).HTMLBody & vbCrLf
sResult = sResult & "----------" & vbCrLf
Next
MsgBox (sResult)
End Sub ' TestOutlookSearch
On Jan 22, 3:32 pm, mad.scientist...@gmail.com wrote:
> I needed to see all messages in my "Sent" folder that were sent
> between 6 AM and 9 AM, so I tried
> Advanced Search > Advanced tab > Define more criteria
> with
> Field: Sent
> Condition: between
> Value: 6 am and 9 am
> but it was not returning anything.
>
> A macro should be able to do it, but I have not had any luck getting
> it to work (or finding a decent example that will work in OL 2003).
>
> Can someone post a VBA macro to accomplish the above search or explain
> what is wrong with the code below?
>
> Any help would be much appreciated... thanks
>
> 'this example searches for any messages in Inbox with a subject of
> "Test"
> 'but returns
> 'Run-time error '91':
> 'Object variable or With block variable not set
> Sub TestOutlookSearch()
> Dim oApp As New Outlook.Application
> Dim oSearch As Outlook.Search
> Dim iItem As Integer
> Dim sResult As String
> oSearch = oApp.AdvancedSearch("Inbox",
> "urn:schemas:mailheader:subject = 'Test'", True, "") ' search string/
> schema examples?
> Set oResults = oSearch.Results
> For iItem = 1 To oSearch.Results.Count
> sResult = sResult & oSearch.Results.Item(iItem).SenderName &
> vbCrLf ' what are the other Item properties?
> Next
> MsgBox (sResult)
> End Sub |
|
| Back to top |
|
 |
Sue Mosher [MVP-Outlook]
Joined: 12 Aug 2007 Posts: 656
|
Posted: Tue Jan 22, 2008 9:30 pm Post subject: Re: searching for messages where hour(Sent) >= 6 AM and hour |
|
|
AdvancedSearch is asynchronous. You should not expected it to return immediate results. Instead, use the Application_AdvancedSearchComplete event in the ThisOutlookSession module to get the results from the SearchObject that event passes as a parameter.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
wrote in message @e6g2000prf.googlegroups.com...
>I needed to see all messages in my "Sent" folder that were sent
> between 6 AM and 9 AM, so I tried
> Advanced Search > Advanced tab > Define more criteria
> with
> Field: Sent
> Condition: between
> Value: 6 am and 9 am
> but it was not returning anything.
>
> A macro should be able to do it, but I have not had any luck getting
> it to work (or finding a decent example that will work in OL 2003).
>
> Can someone post a VBA macro to accomplish the above search or explain
> what is wrong with the code below?
>
> Any help would be much appreciated... thanks
>
> 'this example searches for any messages in Inbox with a subject of
> "Test"
> 'but returns
> 'Run-time error '91':
> 'Object variable or With block variable not set
> Sub TestOutlookSearch()
> Dim oApp As New Outlook.Application
> Dim oSearch As Outlook.Search
> Dim iItem As Integer
> Dim sResult As String
> oSearch = oApp.AdvancedSearch("Inbox",
> "urn:schemas:mailheader:subject = 'Test'", True, "") ' search string/
> schema examples?
> Set oResults = oSearch.Results
> For iItem = 1 To oSearch.Results.Count
> sResult = sResult & oSearch.Results.Item(iItem).SenderName &
> vbCrLf ' what are the other Item properties?
> Next
> MsgBox (sResult)
> End Sub
> |
|
| Back to top |
|
 |
JP
Joined: 21 Nov 2007 Posts: 33
|
Posted: Tue Jan 22, 2008 6:50 pm Post subject: Re: searching for messages where hour(Sent) >= 6 AM and hour |
|
|
This worked for me.
Sub CheckSentTime()
Dim olNS As Outlook.NameSpace
Dim olInbox As Outlook.MAPIFolder
Dim Item As Outlook.MailItem
Set olNS = GetNamespace("MAPI")
Set olInbox = olNS.Folders("Mailbox - Jimmy Pena").Folders("Sent
Items")
For Each Item In olInbox.Items.Restrict("[CreationTime] < '9:00
AM' And [CreationTime] > '6:00 AM'")
Debug.Print Item.Subject & " " & Item.CreationTime
Next Item
Set olInbox = Nothing
Set olNS = Nothing
End Sub
Just replace my name with yours (if you are in an Exchange
environment), or change the line to "Set olInbox =
olNS.GetDefaultFolder(olFolderSentMail)"
HTH,
JP
On Jan 22, 3:32 pm, mad.scientist...@gmail.com wrote:
> I needed to see all messages in my "Sent" folder that were sent
> between 6 AM and 9 AM, so I tried
> Advanced Search > Advanced tab > Define more criteria
> with
> Field: Sent
> Condition: between
> Value: 6 am and 9 am
> but it was not returning anything.
>
> A macro should be able to do it, but I have not had any luck getting
> it to work (or finding a decent example that will work in OL 2003).
>
> Can someone post a VBA macro to accomplish the above search or explain
> what is wrong with the code below?
>
> Any help would be much appreciated... thanks
>
> 'this example searches for any messages in Inbox with a subject of
> "Test"
> 'but returns
> 'Run-time error '91':
> 'Object variable or With block variable not set
> Sub TestOutlookSearch()
> Dim oApp As New Outlook.Application
> Dim oSearch As Outlook.Search
> Dim iItem As Integer
> Dim sResult As String
> oSearch = oApp.AdvancedSearch("Inbox",
> "urn:schemas:mailheader:subject = 'Test'", True, "") ' search string/
> schema examples?
> Set oResults = oSearch.Results
> For iItem = 1 To oSearch.Results.Count
> sResult = sResult & oSearch.Results.Item(iItem).SenderName &
> vbCrLf ' what are the other Item properties?
> Next
> MsgBox (sResult)
> End Sub |
|
| Back to top |
|
 |
mad.scientist.jr
Joined: 22 Jan 2008 Posts: 4
|
Posted: Tue Jan 22, 2008 9:00 pm Post subject: Re: searching for messages where hour(Sent) >= 6 AM and hour |
|
|
That makes sense - however there is no
Application_AdvancedSearchComplete event in the ThisOutlookSession
module. Can you (or someone) post sample code? Thanks...
On Jan 22, 4:30 pm, "Sue Mosher [MVP-Outlook]"
wrote:
> AdvancedSearch is asynchronous. You should not expected it to return immediate results. Instead, use the Application_AdvancedSearchComplete event in the ThisOutlookSession module to get the results from the SearchObject that event passes as a parameter.
>
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook 2007 Programming:
> Jumpstart for Power Users and Administrators
> http://www.outlookcode.com/article.aspx?id=54
>
> wrote in message@e6g2000prf.googlegroups.com...
> >I needed to see all messages in my "Sent" folder that were sent
> > between 6 AM and 9 AM, so I tried
> > Advanced Search > Advanced tab > Define more criteria
> > with
> > Field: Sent
> > Condition: between
> > Value: 6 am and 9 am
> > but it was not returning anything.
>
> > A macro should be able to do it, but I have not had any luck getting
> > it to work (or finding a decent example that will work in OL 2003).
>
> > Can someone post a VBA macro to accomplish the above search or explain
> > what is wrong with the code below?
>
> > Any help would be much appreciated... thanks
>
> > 'this example searches for any messages in Inbox with a subject of
> > "Test"
> > 'but returns
> > 'Run-time error '91':
> > 'Object variable or With block variable not set
> > Sub TestOutlookSearch()
> > Dim oApp As New Outlook.Application
> > Dim oSearch As Outlook.Search
> > Dim iItem As Integer
> > Dim sResult As String
> > oSearch = oApp.AdvancedSearch("Inbox",
> > "urn:schemas:mailheader:subject = 'Test'", True, "") ' search string/
> > schema examples?
> > Set oResults = oSearch.Results
> > For iItem = 1 To oSearch.Results.Count
> > sResult = sResult & oSearch.Results.Item(iItem).SenderName &
> > vbCrLf ' what are the other Item properties?
> > Next
> > MsgBox (sResult)
> > End Sub |
|
| Back to top |
|
 |
mad.scientist.jr
Joined: 22 Jan 2008 Posts: 4
|
Posted: Tue Jan 22, 2008 9:02 pm Post subject: Re: searching for messages where hour(Sent) >= 6 AM and hour |
|
|
It's not working.
I think I'm seeing issues with that search being asynchronous. Any
example code would help...
>From: Sue Mosher [MVP-Outlook]
>Date: Tue, 22 Jan 2008 16:30:01 -0500
AdvancedSearch is asynchronous. You should not expected it to return
immediate results. Instead, use the Application_AdvancedSearchComplete
event in the ThisOutlookSession module to get the results from the
SearchObject that event passes as a parameter.
On Jan 22, 4:50 pm, JP wrote:
> This worked for me.
>
> Sub CheckSentTime()
>
> Dim olNS As Outlook.NameSpace
> Dim olInbox As Outlook.MAPIFolder
> Dim Item As Outlook.MailItem
>
> Set olNS = GetNamespace("MAPI")
> Set olInbox = olNS.Folders("Mailbox - Jimmy Pena").Folders("Sent
> Items")
>
> For Each Item In olInbox.Items.Restrict("[CreationTime] < '9:00
> AM' And [CreationTime] > '6:00 AM'")
> Debug.Print Item.Subject & " " & Item.CreationTime
> Next Item
>
> Set olInbox = Nothing
> Set olNS = Nothing
>
> End Sub
>
> Just replace my name with yours (if you are in an Exchange
> environment), or change the line to "Set olInbox =
> olNS.GetDefaultFolder(olFolderSentMail)"
>
> HTH,
> JP
>
> On Jan 22, 3:32 pm, mad.scientist...@gmail.com wrote:
>
> > I needed to see all messages in my "Sent" folder that were sent
> > between 6 AM and 9 AM, so I tried
> > Advanced Search > Advanced tab > Define more criteria
> > with
> > Field: Sent
> > Condition: between
> > Value: 6 am and 9 am
> > but it was not returning anything.
>
> > A macro should be able to do it, but I have not had any luck getting
> > it to work (or finding a decent example that will work in OL 2003).
>
> > Can someone post a VBA macro to accomplish the above search or explain
> > what is wrong with the code below?
>
> > Any help would be much appreciated... thanks
>
> > 'this example searches for any messages in Inbox with a subject of
> > "Test"
> > 'but returns
> > 'Run-time error '91':
> > 'Object variable or With block variable not set
> > Sub TestOutlookSearch()
> > Dim oApp As New Outlook.Application
> > Dim oSearch As Outlook.Search
> > Dim iItem As Integer
> > Dim sResult As String
> > oSearch = oApp.AdvancedSearch("Inbox",
> > "urn:schemas:mailheader:subject = 'Test'", True, "") ' search string/
> > schema examples?
> > Set oResults = oSearch.Results
> > For iItem = 1 To oSearch.Results.Count
> > sResult = sResult & oSearch.Results.Item(iItem).SenderName &
> > vbCrLf ' what are the other Item properties?
> > Next
> > MsgBox (sResult)
> > End Sub |
|
| Back to top |
|
 |
Sue Mosher [MVP-Outlook]
Joined: 12 Aug 2007 Posts: 656
|
Posted: Wed Jan 23, 2008 2:34 am Post subject: Re: searching for messages where hour(Sent) >= 6 AM and hour |
|
|
At the top of the module window, select the Application object from the left dropdown list, then AdvancedSearchComplete from the right dropdown list. That will insert the event handler procedure. Outlook VBA Help has sample code.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
wrote in message @t1g2000pra.googlegroups.com...
> That makes sense - however there is no
> Application_AdvancedSearchComplete event in the ThisOutlookSession
> module. Can you (or someone) post sample code? Thanks...
>
> On Jan 22, 4:30 pm, "Sue Mosher [MVP-Outlook]"
> wrote:
>> AdvancedSearch is asynchronous. You should not expected it to return immediate results. Instead, use the Application_AdvancedSearchComplete event in the ThisOutlookSession module to get the results from the SearchObject that event passes as a parameter.
>
>> wrote in message@e6g2000prf.googlegroups.com...
>> >I needed to see all messages in my "Sent" folder that were sent
>> > between 6 AM and 9 AM, so I tried
>> > Advanced Search > Advanced tab > Define more criteria
>> > with
>> > Field: Sent
>> > Condition: between
>> > Value: 6 am and 9 am
>> > but it was not returning anything.
>>
>> > A macro should be able to do it, but I have not had any luck getting
>> > it to work (or finding a decent example that will work in OL 2003).
>>
>> > Can someone post a VBA macro to accomplish the above search or explain
>> > what is wrong with the code below?
>>
>> > Any help would be much appreciated... thanks
>>
>> > 'this example searches for any messages in Inbox with a subject of
>> > "Test"
>> > 'but returns
>> > 'Run-time error '91':
>> > 'Object variable or With block variable not set
>> > Sub TestOutlookSearch()
>> > Dim oApp As New Outlook.Application
>> > Dim oSearch As Outlook.Search
>> > Dim iItem As Integer
>> > Dim sResult As String
>> > oSearch = oApp.AdvancedSearch("Inbox",
>> > "urn:schemas:mailheader:subject = 'Test'", True, "") ' search string/
>> > schema examples?
>> > Set oResults = oSearch.Results
>> > For iItem = 1 To oSearch.Results.Count
>> > sResult = sResult & oSearch.Results.Item(iItem).SenderName &
>> > vbCrLf ' what are the other Item properties?
>> > Next
>> > MsgBox (sResult)
>> > End Sub
>
|
|
| Back to top |
|
 |
|
|
| Related Topics: | Need help searching for "\\192" in body of new email Hi, It's rare I post for help without thoroughly searching, but I can't seem to find anything on this. We get automated email pointing to a network share for a file that is accessed by everyone. However, we need to copy it over to our local computers befo
Searching by To or From fields (Outlook 2003) Hello! I am trying to write a simple macro that will search for e-mails sent or received within the last 3 months to or from the given e-mail address. A common function when you want to find all mail communication related to some person. The search code i
Importing e-amil messages I am converting from an NDS e-mail client to microsoft Outlook 2002. How can I import these old emails into a users outlook pst file. if not via vba, then how?
Internet Format of the messages Hi! Something went wrong (I don't know how) on my Microsoft Outlook 2003 (fully patched with SP2 and fixes). In my personal Address Books (3600 addresses), some contacts are wrong with the Internet Format which is "Send using Outlook Rich Text Format" and
selections in text messages Hi, Is it possible to obtain a selection in a text message? I can get to the body via but I don't see a way to get just a selection from such a body. |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|