PDA

View Full Version : Automatically replacing text in subject lines



dgoldstein
04-28-2005, 10:55 AM
Our Exchange server is set to mark certain e-mail messages as unwanted, adding various text strings to their subject lines before passing the message through to the Outlook client. I have a Word macro that removes these specific text strings from subject lines; I cut from the Outlook subject line, paste into Word, run the macro, cut the result from Word, and paste back into the subject line. Whew.

Is it possible to create an Outlook macro that deletes a specified string from the subject line of incoming e-mail?

Thanks,

Dan Goldstein

MOS MASTER
04-28-2005, 11:32 AM
Hi Dan,

Welcome to VBAX! :hi:

You can use an outlook rule (for incoming mail) to accomplice this. In the rule assign the Macro with "run a script" option in Step 2 off the rule wizard!

The code could look something like this: (insert in Normal code Module)
Sub StripSubject(oItem As Outlook.MailItem)
Dim iDelete As Integer
Dim sDelete As String
Dim sOld As String
Dim sNew As String

sDelete = "Hi Dan"
With oItem
sOld = .Subject
iDelete = InStr(1, .Subject, "Hi Dan", vbTextCompare)

If iDelete <> 0 Then
sNew = Replace(sOld, sDelete, "", 1, -1, vbTextCompare)
.Subject = Trim(sNew)
.Save
End If
End With
End Sub

Enjoy! :thumb