jana
asked on
Is there a way to have a VBA script for Outlook 2007 to display the latest email in Inbox
We need have the user know the last email that has been received that has a specific value. Is there a way to go about in a VBA script?
We could check for the string in each mail as received and update each time ... Question is how do want to view the mail I.e. we could save a copy each time deleting the old one in a specific folder
ASKER
Something like is what we are searching for.
To be exact, what we want is to have a button where when click it will display by a MsgBox the last email received that email of the sender has "MCAGROUP".
To be exact, what we want is to have a button where when click it will display by a MsgBox the last email received that email of the sender has "MCAGROUP".
Do you insist of a message box? I would instead just open the email itself.
And what exactly do you mean with "of the sender has "MCAGROUP""? Do you mean it is from a specific person, or company, both reflected by the sender's email address?
Further, is the email to be searched for only in one specific folder, say Inbox, or could it have been moved, and we need to search in several folders?
And what exactly do you mean with "of the sender has "MCAGROUP""? Do you mean it is from a specific person, or company, both reflected by the sender's email address?
Further, is the email to be searched for only in one specific folder, say Inbox, or could it have been moved, and we need to search in several folders?
ASKER
Here the answers:
- Do you insist of a message box? I would instead just open the email itself.
Answ: Yes. That could be it; always filtering the emails by "MCAGROUP"
- And what exactly do you mean with "of the sender has "MCAGROUP""? Do you mean it
is from a specific person, or company, both reflected by the sender's email address?
Answ: we mean that we need to view all senders emails address and choose the
most recent email that the email has within its addres "MCAGROUP". For example,
"MCAGROUP@domain.com or RoyMCagroup@domain.com"
- Further, is the email to be searched for only in one specific folder, say Inbox, or
could it have been moved, and we need to search in several folders?
Answ: Yes, only inbox
Hope this helps, help us.
Thanx in advance
- Do you insist of a message box? I would instead just open the email itself.
Answ: Yes. That could be it; always filtering the emails by "MCAGROUP"
- And what exactly do you mean with "of the sender has "MCAGROUP""? Do you mean it
is from a specific person, or company, both reflected by the sender's email address?
Answ: we mean that we need to view all senders emails address and choose the
most recent email that the email has within its addres "MCAGROUP". For example,
"MCAGROUP@domain.com or RoyMCagroup@domain.com"
- Further, is the email to be searched for only in one specific folder, say Inbox, or
could it have been moved, and we need to search in several folders?
Answ: Yes, only inbox
Hope this helps, help us.
Thanx in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked perfectly!!!
Please give us a brief explanation the following lines for our benefit:
-> strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:from email" & Chr(34)
& " like " & "'%" & "mcagroup" & "%'"
-> Set filteredItems = olFolder.Items.Restrict(st rFilter)
-> filteredItems.Sort "receivedtime", True
Please give us a brief explanation the following lines for our benefit:
-> strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:from
& " like " & "'%" & "mcagroup" & "%'"
-> Set filteredItems = olFolder.Items.Restrict(st
-> filteredItems.Sort "receivedtime", True
-> strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:from email" & Chr(34)
& " like " & "'%" & "mcagroup" & "%'"
Creates a string to use in the restriction
It is called a DASL query and is what outlook uses when you set up a filter on a folder using the application filter option.
The leading and trailing % signs act as wildcards for DASL filters so in normal *mcagroup*
The rest is simply the required syntax
-> Set filteredItems = olFolder.Items.Restrict(st rFilter)
Takes the string and in this case process the inbox, (olfolder) items to return only those with mcagroup in the addy
-> filteredItems.Sort "receivedtime", True
SImply sorts the collection of mcagroup senders according to receiver date so that we know exactly which is the newest
Chris
& " like " & "'%" & "mcagroup" & "%'"
Creates a string to use in the restriction
It is called a DASL query and is what outlook uses when you set up a filter on a folder using the application filter option.
The leading and trailing % signs act as wildcards for DASL filters so in normal *mcagroup*
The rest is simply the required syntax
-> Set filteredItems = olFolder.Items.Restrict(st
Takes the string and in this case process the inbox, (olfolder) items to return only those with mcagroup in the addy
-> filteredItems.Sort "receivedtime", True
SImply sorts the collection of mcagroup senders according to receiver date so that we know exactly which is the newest
Chris
BTW, the line:
Set folderItems = olFolder.Items
was left over from a bit of cut and paste on another question so is not needed here ... as you might already have realised.
Chris
Set folderItems = olFolder.Items
was left over from a bit of cut and paste on another question so is not needed here ... as you might already have realised.
Chris
ASKER
Thank you very much!
Please see the EE link below, it's a question placed that maybe it can be solved similar how you assisted us here.
https://www.experts-exchange.com/questions/27499402/s-there-a-way-to-have-a-VBA-script-for-Outlook-2007-to-display-the-latest-email-in-Inbox-searchin-a-User-Define-filed.html
We'll proceed to close the question.
Please see the EE link below, it's a question placed that maybe it can be solved similar how you assisted us here.
https://www.experts-exchange.com/questions/27499402/s-there-a-way-to-have-a-VBA-script-for-Outlook-2007-to-display-the-latest-email-in-Inbox-searchin-a-User-Define-filed.html
We'll proceed to close the question.
ASKER
Thax
There are a lot of other options, like marking the mail by VBA code on receive, or the like. What do you want to see exactly? Would it be sufficient to have a button doing the search and display on demand?