Create an outlook VBA to forward an email with specific words in the subject line

1

Hello I want to create a rule or a vba in outlook, where the subject line has 3 certain words in any order. For instance, I want to look for "Badges, user, moped"

Subject says: the badges and the user with a moped.

If the subject has those three words in it, then I want it to forward the email to someone.

found this code created by "mark-goldfain", I was thinking maybe we can modify it? Although I do not know anything about VBA programming.

Public Sub File_Stock_Incoming_Message(Item As Outlook.MailItem)
  ' This macro is called from a wizard-built rule, where the
  ' rule operates on *every* incoming message, and its action
  ' is to call this macro.
  Dim NS As Outlook.NameSpace
  Set NS = Application.Session
  Dim MoveToFolder As Outlook.MAPIFolder
  Set MoveToFolder = NS.Folders("mainboxname").Folders("MsgLog")

  Dim sbjstr As String
  sbjstr = Item.Subject
  If (sbjstr = "Whatever Site Error") Then
    Item.Move MoveToFolder
  End If
End Sub

Juan Flores

Posted 2015-12-09T19:01:53.250

Reputation: 11

Why not just use a rule? – Raystafarian – 2015-12-10T12:00:54.413

Let me give this a try and will let you know if it works. Also, how would you tell the VBA to forward the email to : joe@joe.com? – Juan Flores – 2015-12-10T21:20:42.140

Raystafarian, The reason that I don't want to use a rule, is that I am looking for just 3 specific words in the subject. So, it would be if , word 1 and word 2 and word 3 exist in the subject. Forward the email to someone@someon.com. – Juan Flores – 2015-12-10T22:54:34.433

Answers

0

You just need to change the condition of If:

instr(item.subject,"word1")>0 And instr(item.subject,"word2")>0 And instr(item.subject,"word3")>0

Máté Juhász

Posted 2015-12-09T19:01:53.250

Reputation: 16 807

Please don't post your comments an answer. You always can comment in your own question. – Máté Juhász – 2015-12-10T04:49:48.350