Craig
Craig

Reputation: 573

Outlook VBA macro appears not to be executing

I would like to redirect a message received from a specific email to another email address. The email address to which the message will be redirected to will never be the same.

I thought of using scripts to accomplish this, where the email address to which the email must be redirected to subject of the email. The format of the subject of the original message is:

subject/[email protected]

I have written the following script but when the rule executes the script nothing happens. Can you pleas tell me what mistake I made and why this script appears to do nothing?

Sub CodeSubjectForward(Item As Outlook.MailItem)
  Dim txt As String
  Dim EAddress As String
  Dim Temp As String
  Dim pos

  txt = Item.Subject
  pos = InStr(txt, "/")
  Temp = Left(txt, pos - 1)
  EAddress = Right(txt, Len(txt) - pos - 1)

  Dim objMsg As MailItem
  Set objMsg = Application.CreateItem(olMailItem)

  objMsg.body = Item.body
  objMsg.Subject = Temp
  objMsg.Recipients.Add EAddress

  objMsg.Display
End Sub

Upvotes: 0

Views: 144

Answers (1)

niton
niton

Reputation: 9199

Open a mailitem that fits the rule conditions and step through this.

Option Explicit

Private Sub CodeSubjectForward_Test()
    Dim currItem As MailItem
    Set currItem = ActiveInspector.currentItem
    CodeSubjectForward currItem
End Sub

If you get to CodeSubjectForward then the rule conditions are not correct.

Upvotes: 1

Related Questions