I want Outlook to perform an action on email from a certain email address.
In the ThisOutlookSession I have:
Private Sub Application_NewMail() 'This triggers when a new email is recieved
Call TestSub
End Sub
In a module I have:
Public Sub TestSub()
Dim Msg As Outlook.MailItem
Dim FromEmailAddress As String
FromEmailAddress = Msg.SenderEmailAddress
If FromEmailAddress = "Test@example.com" Then
MsgBox ("Hello")
End If
End Sub
I get
Run-time error '91':
Object variable or With block variable not set
on FromEmailAddress = Msg.SenderEmailAddress
.
I have tried many variations on my code and exhausted the powers of Google.