Extract text from the message body and show in msgbox

G

Guest

Hi All,

First of all heres my code :

Sub cliams()
Dim myItem As Outlook.Inspector
Dim objItem As Object
Dim I As Integer
Dim x As Long

Dim xat As String
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
Set objItem = myItem.CurrentItem
mybody = objItem.Body
I = Len(mybody)

While x < I
If Mid(mybody, 3, x) = "At:" Then
xat = Mid(mybody, 3, x)
End If
x = x + 1
Wend
MsgBox ("Branch = " & xat & Chr(13) & Chr(10))
End Sub

So heres my problem. I get a forwarded an email - within the message body
there is certain information that I need to see. The body of message is not
that well layed out, but it is always in the same format.

My thoughts are to go through the body of the message and look for key words
and the extract the following text information - as per my example.

I seem to be going astray somewhere with the mid function - I have tried mid$.
I have also tried using a for loop.

Any thoughts - or help

Many thanks
 
G

Guest

Why not use the Instr() function to search for the exact location of "At:",
then use Mid() to extract text:

pos = Instr(myBody, "At:")
If pos > 0 Then
xat = Mid(myBody, pos+3)
End If

Note that the 2nd parameter in Mid() is the start parameter, while the last
and optional parameter is the length)
 

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