Remove text in subject using VBA

danlyng

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
#1
Hi,

In my company there has been made a new feature whenever we get an email from an external sender.

Text i subject can now be: "[CAUTION: EXTERNAL EMAIL] Agenda for meeting wednesday" as before it would just have stated "Agenda for meeting wednesday"

The annoying thing about it is that the text [CAUTION: EXTERNAL EMAIL] does not remove itself when I send a reply.
I would like af code to put into ThisOutlookSession.

I have tried this one but without luck:

Sub mymacro ()
dim arr as variant,i as long
arr=array("[CAUTION: EXTERNAL EMAIL]")
for i=0 to ubound(arr)
oitem.subject=replace(oitem.subject,arr(i),"",,,vbtextcompare)
next
oitem.subject=trim(oitem.subject)
oitem.save
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#2
is that the only test you need to replace? if so, don't use the arrary.
oitem.subject=replace(oitem.subject,"[CAUTION: EXTERNAL EMAIL]","")

if you want ot use an array, see Using Arrays in Outlook macros
try For i = LBound(arr) To UBound(arr)
 
Top