Items.Find – Can this be used to find text in the body of an email? I have
already narrowed the Items I am looking at down to as few as possible by
using a rule. The only way I know now which emails I want (or not) is by
check to see if there are certain words in the body text.
To do this I have used this:
For ItemReference = olMail.Count To 1 Step -1
MessageText = olMail(ItemReference).Body
If InStr(MessageText, "my text") > 0 Then
‘ Then Parse MessageText to get the various bits of info I need
Sue as for the rest of your comments I don’t mean to be rude, but “you speak
with forked tongue
â€. I am not a professional developer and have never done
any coding in Outlook and you clearly are one of the guru’s in this area.
I have made some changes that sort of work and have include the full sub
routines below:
I realize NewMailEx is looking at my mailbox and not the shared mailbox, but
it is a way of periodically checking the shared mailbox. I feel you cringing
already
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Call ProcessEmails
End Sub
Private Sub Application_Startup()
Call ProcessEmails
End Sub
Private Sub ProcessEmails()
Dim DeletedFolder As Outlook.MAPIFolder
Dim olNS As NameSpace
Dim InputFolder As Outlook.MAPIFolder
Dim ProcessedFolder As Outlook.MAPIFolder
Set olNS = Outlook.Application.GetNamespace("MAPI")
Set InputFolder = olNS.Folders("Mailbox - Partners").Folders("Order
Notification")
Set ProcessedFolder = olNS.Folders("Mailbox - Partners").Folders("Order
Notification Processed")
Set DeletedFolder = olNS.Folders("Mailbox - Partners").Folders("Deleted
Items")
Dim MessageText As String
Dim ItemReference As Integer
Dim olMail As Items
' Get reference to items in folder
Set olMail = InputFolder.Items
For ItemReference = olMail.Count To 1 Step -1
On Error Resume Next
MessageText = olMail(ItemReference).Body
If Err <> 0 Then MessageText = ""
On Error GoTo 0
If InStr(MessageText, "my text ") > 0 Then
' Parse this email.
Call ParseEmail(MessageText, GoodReturn)
BookingElement(18) = olMail(ItemReference).ReceivedTime
If GoodReturn Then
Call WriteTransactionFile(GoodReturn)
If GoodReturn Then
olMail(ItemReference).UnRead = False
olMail(ItemReference).Move ProcessedFolder
On Error Resume Next
olMail(ItemReference).UnRead = False ' Per suggestion
from Ken Slovak re maybe having to set this twice.
On Error GoTo 0
End If
End If
Else
olMail(ItemReference).Move DeletedFolder
End If
Next ItemReference
Set InputFolder = Nothing
Set ProcessedFolder = Nothing
Set olNS = Nothing
Set olMail = Nothing
End Sub