Outlook 2013规则,运行脚本以更新主题和转发邮件

时间:2014-11-18 09:21:07

标签: vba email outlook-vba outlook-2013

我正在尝试创建一个脚本,在转发之前将文本添加到电子邮件的主题中。这是我第一次写一篇。

我的标准是根据规则设定的。该脚本将检查主题。根据主题中的文字,它将添加特定文本。

例如,我收到的电子邮件中包含主题中的JobsDB,然后应该添加到主题的文本是Jobs DB。如果主题不包含JobsDB,那么将转到下一个IF以检查它是否包含Indeed。如果没有,它将转到另一个IF来检查它是否包含LinkedIn。

当前代码:

Sub ForwardEmailIndeed(Item As Outlook.MailItem)

Set myForward = Item.Forward

If Item.Subject.Contains("Indeed") Then
    myForward.Subject = Item.Subject & ("Indeed")

If Item.Body.Contains("s1JOBS") Then
    myForward.Subject = Item.Subject & ("S1 Jobs")

If Item.Subject.Contains("JobsDB") Then
    myForward.Subject = Item.Subject & ("JobsDB")

If Item.Subject.Contains("TradeWindsJobs") Then
    myForward.Subject = Item.Subject & ("Tradewinds")

If Item.From.Contains("auto@oilandgasjobsearch.com") Or _
  Item.Body.Contains("oilandgasjobsearch.com") Then
    myForward.Subject = Item.Subject & ("Oil&Gas JobSearch")

If Item.From.Contains("LinkedIn") Or _
  Item.Body.Contains("LinkedIn") Then
    myForward.Subject = Item.Subject & ("Linkedin Advert")

End If

myForward.Recipients.Add "email@yahoo.com"

myForward.Send

End Sub

我的规则正常但脚本无效。

此守则以前适用于我。

Sub ForwardEmail(Item As Outlook.MailItem)

    Set myForward = Item.Forward

    myForward.Subject = Item.Subject & (“Indeed”)
    myForward.Recipients.Add “email@yahoo.com”
    myForward.Send

End Sub

它不再起作用了。它没有任何转发。

1 个答案:

答案 0 :(得分:0)

您正在寻找InStr not Contains。

http://msdn.microsoft.com/en-us/library/office/gg264811%28v=office.15%29.aspx

Option Explicit

Private Sub ForwardEmailIndeed_test()
' Open a mailitem first
Dim curritem As mailitem
Set curritem = ActiveInspector.currentItem
ForwardEmailIndeed curritem
End Sub


Sub ForwardEmailIndeed(Item As Outlook.mailitem)

Dim myForward As mailitem

Set myForward = Item.Forward

If InStr(Item.Subject, "Indeed") Then
    myForward.Subject = Item.Subject & ("Indeed")
End If

If InStr(Item.body, "s1JOBS") Then
    myForward.Subject = Item.Subject & ("S1 Jobs")
End If

If InStr(Item.Subject, "JobsDB") Then
    myForward.Subject = Item.Subject & ("JobsDB")
End If

If InStr(Item.Subject, "TradeWindsJobs") Then
    myForward.Subject = Item.Subject & ("Tradewinds")
End If

If InStr(Item.SenderEmailAddress, "auto@oilandgasjobsearch.com") Or _
  InStr(Item.body, "oilandgasjobsearch.com") Then
    myForward.Subject = Item.Subject & ("Oil&Gas JobSearch")
End If

If InStr(Item.SenderEmailAddress, "LinkedIn") Or _
  InStr(Item.body, "LinkedIn") Then
    myForward.Subject = Item.Subject & ("Linkedin Advert")
End If

myForward.Recipients.Add ("email@yahoo.com")

myForward.Send

End Sub


Private Sub ForwardEmail_test()
' Open a mailitem first
Dim curritem As mailitem
Set curritem = ActiveInspector.currentItem
ForwardEmailIndeed curritem
End Sub

Sub ForwardEmail(Item As Outlook.mailitem)

Dim myForward As mailitem
Set myForward = Item.Forward

myForward.Subject = Item.Subject & ("Indeed")
myForward.Recipients.Add ("email@yahoo.com")

myForward.Send

End Sub