I'm trying to automatically achieve this workflow:
- when user opens a message draft in Outlook (a generated EML file)
- if the subject matches a string (immutable, known beforehand, I can't change it; it's something like
xyžřy
, note the non-ASCII characters): - then add an e-mail to BCC field (immutable, known beforehand, valid e-mail address; let's say it's
baz@example.com
)
I already know the last part - how to add a BCC to a message, and I use InStr for matching:
Sub addbcc()
Dim objRecip As Recipient
Set oMsg = Application.ActiveInspector.CurrentItem
With oMsg
If InStr(1, oMsg.Subject, "xyžřy") > 0 Then
Set objRecip = oMsg.Recipients.Add("baz@example.com")
objRecip.Type = olBCC
objRecip.Resolve
End If
End With
Set oMsg = Nothing
End Sub
However, the user still needs to remember to press a button to run this macro, which is not more convenient than typing the BCC manually. Is it possible to run the macro automatically when this e-mail is opened?