I have mails like this :
Hello,
Please note we did ... at 16h15
Actions done: Rebuilding etc
sincerely
The carriage return
in the email body is usually vbNewline
This is how I usually do it
Sub Sample()
Dim sBody As String
Dim MyAr
Dim i As Long
'
'~~> Rest of your code
'
sBody = oMail.Body
'~~> For testing purpose
'sBody = "Hello," & vbNewLine & vbNewLine
'sBody = sBody & "Please note we did ... at 16h15" & vbNewLine & vbNewLine
'sBody = sBody & "Actions done: Rebuilding etc" & vbNewLine & vbNewLine
'sBody = sBody & "Sincerely"
'~~> Split the email body on vbnewline and store it in array
MyAr = Split(sBody, vbNewLine)
'~~> Loop through array
For i = LBound(MyAr) To UBound(MyAr)
'~~> Check if the line has "Actions done:"
If InStr(1, MyAr(i), "Actions done:") Then
'~~> This would give you "Rebuilding etc"
'~~> Split the line on "Actions done:"
'~~> You will get an array. Ar(0) will have "Actions done:"
'~~> And Ar(1) will have what you are looking for so we use
'~~> Split()(1) directly to access that item
MsgBox Split(MyAr(i), "Actions done:")(1)
Exit For
End If
Next i
End Sub
Edit
ANOTHER WAY
Try this:
TechnicPosition = InStr(1, .Body, "Actions done: ")
TechnicEndPosition = InStr(TechnicPosition, .Body, Chr(10))
TechnicAction = Mid(.Body, TechnicPosition + 14, TechnicEndPosition - TechnicPosition - 14)
Loop through the body to see what the character is:
For i = 1 To Len(.Body)
If Not Mid(.Body, i, 1) Like "[A-Za-z0-9,'?!"".:]" Then
Debug.Print Asc(Mid(.Body, i, 1))
End If
Next
Once you've found the Asc()
value, split the body on it and return the second index:
TechnicAction = Split(.Body, Asc(10))(1) '// Or whatever Asc() is required