Every time the mail is received, I want to print out a specific word in a body of email:
---------------------------------Body of email-------------------------------------
Sender Name: John
Sender's Address: john@sample-mail.com
Subject: Mail Subject from John <----- the line that I want to get
--------------------------------------End------------------------------------------
My Code:
Private WithEvents olItems As Outlook.Items
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
End Sub
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olItems = olNS.GetDefaultFolder(olFolderInbox).Folders("Watchlisted").Items
End Sub
Private Sub olItems_ItemAdd(ByVal Item As Object)
Dim BodySubjLine As String, BodySubj As Variant
Dim olMail As Outlook.MailItem
Dim olAtt As Outlook.Attachment
Set olMail = Item
BodySubj = Split(olMail.Body, vbNewLine)
BodySubjLine = Trim(BodySubj(2))
Debug.Print BodySubjLine
Set olMail = Nothing
End Sub
Expected output:
Subject: Mail Subject from John
The output I get gives nothing at all