Search structured text in Outlook body

finalSubj = ParseTextLinePair(initialBod, "Mailbox:")

See “Listing 17.1. Extract data from a structured text block”. https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2007/dd492012(v=office.12)

Function ParseTextLinePair(strSource As String, strLabel As String)
Dim intLocLabel As Integer
Dim intLocCRLF As Integer
Dim intLenLabel As Integer
Dim strText As String

' locate the label in the source text
intLocLabel = InStr(strSource, strLabel)
intLenLabel = Len(strLabel)
    If intLocLabel > 0 Then
    intLocCRLF = InStr(intLocLabel, strSource, vbCrLf)
    If intLocCRLF > 0 Then
        intLocLabel = intLocLabel + intLenLabel
        strText = Mid(strSource, _
                        intLocLabel, _
                        intLocCRLF - intLocLabel)
    Else
        intLocLabel = Mid(strSource, intLocLabel + intLenLabel)
    End If
End If
ParseTextLinePair = Trim(strText)
End Function

Note: The OP indicated the line that worked was

finalSubj = ParseTextLinePair((CStr(initialBod)), "Mailbox:") 

Leave a Comment