如果声明多个条件

时间:2017-07-27 12:21:40

标签: vba email outlook outlook-vba

我正在制作一个转发邮件的脚本,如果收件人,发件人和主题是正确的。对于前者

如果一切都为真,则转发邮件:

  • 来自:OneGuy@mail.com
  • 致:OtherGuy@mail.com
  • 主题:你好Or

这是我目前的剧本

Public Sub FW(olItem As Outlook.MailItem)

Dim Msg As Outlook.MailItem
Set Msg = Item

    If Msg.SenderEmailAddress = "OneGuy@mail.com" Then
    ElseIf Msg.To = "OtherGuy@mail.com" Then
    ElseIf Msg.Subject = "Hallo" Then
    ElseIf Msg.Subject = "Hi" Then

        Dim olForward As Outlook.MailItem
        Set olForward = olItem.Forward

        With olForward
            'Stuff happens here that work properly 
        End With

    End If    

    '// Clean up
    Set olItem = Nothing
    Set olForward = Nothing
    Set Msg = Nothing
End Sub

1 个答案:

答案 0 :(得分:3)

If Msg.SenderEmailAddress = "OneGuy@mail.com" AND Msg.To = "OtherGuy@mail.com" AND Msg.Subject = "Hallo" AND Msg.Subject = "Hi" Then