0
votes

My project is to extract the details ("Conversation Id", "Date Created", "Sender", "Sender's Name", "Sender's e-mail", "Subject", "To", "Recipients", "Entry ID") of a email items from selected Outlook folder (ex: ABC Services) and create an Excel database. I have successfully extracted the same to Excel spreadsheet.

I am facing a problem in fetching the name from the signature from each of the email items.

My team on daily basis checks the mail from an Outlook folder (ex: ABC Services) and replies with common sender mail ID (ex: [email protected]) with their respective signatures (varies according to sender ex: Vinay MG, Povel A, James Car etc.) in email body.

I want to extract the sender name from the signature. I came to know about "Suggestedsigner" from MS office site, but didn't understand much. Also I searched many sites, but no success.

My email flows as below,

[..... ..... EMail BODY... .... ... ]
Regards,
Vinay M G | ABC Services | EFG Team
XXX Company, Location
Mob: xx-xxxxx xxxxx

I want to extract name (Vinay M G) from the signature.

1
Can you post example on how the signature looks like? you may also wanna post your current code - 0m3r

1 Answers

0
votes

Text can be parsed out of the body.

Option Explicit

Sub parseBodyForText()

    ' Test this sample code in Outlook not Excel

    ' Where mail contains a line in this format
    '  name | ABC Services | EFG Team

    Dim myItem As Object
    Dim bodyLines() As String
    Dim namelineWords() As String
    Dim i As Long

    ' Open applicable mail
    Set myItem = ActiveInspector.CurrentItem

    If myItem.Class = olMail Then

        bodyLines = Split(myItem.Body, vbCrLf)

        For i = LBound(bodyLines) To UBound(bodyLines)

            ' Attempt to determine the applicable line

            'If Right(bodyLines(i), 10) = "| EFG Team" Then
            ' or
            'If InStr(bodyLines(i), "| ABC Services |") Then

            ' If the above strings are not always present.
            ' Perhaps search for the "|"
            ' Increases chance of false positives
            If InStr(bodyLines(i), " | ") Then

                Debug.Print "nameline: " & bodyLines(i)

                namelineWords = Split(bodyLines(i), "|")
                Debug.Print "first element of namelineWords array: " & namelineWords(0)

                ' Assumes no false positives
                Exit For

            End If

        Next

    End If

End Sub