我创建了一个Outlook宏,如果我想发送除列出的电子邮件ID以外的其他电子邮件,它将弹出一个对话框。但是,我无法将多个电子邮件ID添加到列表中。请找到我编写的以下代码。有人可以帮我如何在下面的代码中添加多个电子邮件ID吗?
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Const ADDR_TO_WATCH_FOR = "James.t@outlook.com"
Dim olkRec As Outlook.Recipient
If Item.Class = olMail Then
For Each olkRec In Item.Recipients
If LCase(olkRec.Address) <> ADDR_TO_WATCH_FOR Then
If MsgBox("This message is addressed to " & ADDR_TO_WATCH_FOR & ". Are you sure you want to send it?", vbQuestion + vbYesNo, "Confirm Send") = vbNo Then
Cancel = True
End If
Exit For
End If
Next
End If
Set olkRec = Nothing
End Sub
答案 0 :(得分:0)
不在循环内的所有收件人上显示消息框。首先运行循环并检查所有收件人。如有必要,建立多个收件人的列表。退出循环后,检查该列表(字符串)是否不为空,显示消息框。