Selection.Find is Word's method for searching inside text. Inside an Outlook item, you would use the Instr() function to test for a match inside the MailItem.Body
If Instr(obj.Body, "Description: Successful" 0 Then
obj.Delete
End If
The tricky part is how your construct the loop. Because the index changes each time you delete an item, you can't use a For Each ... Next loop, but can instead us a countdown loop:
count = Items.Count
For i = count to 1 Step -1
Set obj = Items(i)
If Instr(obj.Body, "Description: Successful" 0 Then
obj.Delete
End If
Next
You can put the code in ThisOutlookSession or create a new module, which would make it easier to export for backup.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"Joanne" wrote in message ...
Daily I receive approx 100 emails. I have to open them individually
and verify that this line is present
Description: Successful
If it is present, I delete the email.
I think I should be able to do this programmatically, looping thru all
the emails in the collection and maybe doing a ctrl/find to locate the
text string and if it is present, close (maybe I don't have to close
it first?) and then delete the email. If the string is not present,
close the email and goto the next one without deleting. I am a bit
familiar with VBA in Word but rather outside my league here in
Outlook.
Here is my best guess on how to approach this and at least get
started:
Public Sub Deletions()
Dim obj As Object
Dim Items As Outlook.MailItem
Set Items = Application.Session.GetDefaultFolder(olFolderInbox ).Items
For Each obj In ItemsI
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Description: Successful"
here I think I need an if then statement saying if the
string is present, delete the item, if not close the item
only I can't think through it enough to figure out how to
tell the program that the text is indeed there (or not!)
End With
Next
End Sub
Would it be best to put the code to do this in the
'ThisOutlookSession' Module? I've never used the module and am not at
all sure when it should be used as verses just creating a new module.