Ok with 7 hours of googling this is how far i've got - I'm stuck on the Split function (nr bottom) bit though as my email address line contains tabs and spaces and i can't find out how to tell it i only want the bit around the @
Sub plain(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim emailtosend As String
strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
olMail.BodyFormat = olFormatPlain
olMail.Save
Set Msg = olNS.GetItemFromID(MyMail.EntryID)
Msg.BodyFormat = olFormatPlain
'CALL THE SUB TO PARSE BODY TEXT AND GET THE EMAIL
emailtosend = SearchBody(Msg.Body)
If emailtosend “” Then
Set NewForward = Msg.Forward
With NewForward
.Subject = Msg.Subject
.To = emailtosend
.Body = Msg.Body
.Send
End With
With Msg
.UnRead = False
.FlagStatus = olNoFlag
End With
Else
GoTo ExitProc
End If
ExitProc:
Set NewForward = Nothing
Set Msg = Nothing
Set objItem = Nothing
End Sub
Function SearchBody(msgbody) As String
lines = Split(msgbody, vbCrLf)
'–GET THE EMAIL TO SEND TO
For Each Line In lines
If InStr(Line, "Email Address") Then
parsed = Split(Line, ":")
If InStr(parsed(1), "@") Then
'return the email address
SearchBody = parsed(1)
End If
End If
Next
End Function
Last edited by annabel : June 23rd 10 at 09:50 AM.
|