extract email from message body

E

Ed

Tried InStr and AdvancedSearch. the latter requries a whole second routine
to catch the results of the search, but I'm not sure it is capable of
capturing from a MAPI file. This works, but I can't figure out how to
capture the result:

Dim objSch As Search
Const strF As String = "urn:schemas:httpmail:textdescription LIKE '<%>'"
Const strS As String = "undeliverables"
Const strTag As String = "GITem"
Set objSch = Application.AdvancedSearch(Scope:=strS, _
Filter:=strF, Tag:=strTag)

I cannot figure out how to get the InStr function to return anything but a
boolean (false).

sorry if I confused some terminology.
 
M

Michael Bauer [MVP - Outlook]

Why don't you try the sample for AdvancedSearch that I gave you with my last
post? Your code doesn't work, that's right.

if you prefer to loop through all of the items and search with Instr: That
function returns the postion of the found string - if any. Then you must use
the Left and/or Right functions to get the string left and/or right side
from that position.

As it's hard to follow the thread you messed up totally, here's a sample for
a loop in *principle*:

Dim obj as Object
Dim Items as Outlook.Items
Dim Folder as Outlook.Mapifolder
Dim i as Long
Dim Pos1 as Long,Pos2 as Long
Dim SLeft as String, SMiddle as String, SRight As String

Set Folder=Application.Session.GetDefaultFolder(olFolderInbox)
Set Items=Folder.Items
For i=1 to Items.Count
Set obj=Items(i)
Pos1= Instr(1,obj.Body,"whatever",vbTextCompare)
If Pos1>0 Then
' "whatever" is found
Pos2=pos1+Len("whatever")
' get the text left hand from the searched phrase
SLeft = Left$(obj.Body,Pos1-1)
' get the text right hand from the searched phrase
SRight = Mid$(obj.Body,Pos2+1)
' get the text searched phrase itself
SMiddle = Mid$(obj.Body,Pos1,Pos2+1-Pos1)
Endif
Next

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - Categorize Outlook data:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Thu, 3 May 2007 18:01:01 -0700 schrieb Ed:
 

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