我正在编写一个查看收件人地址的宏,如果某个名称显示vbYesNo msgbox。然而它向我展示了msgbox(Aaron Islam)。
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error Resume Next
' use lower case for the address
' LCase converts all addresses in the To field to lower case
RecipientsName = Item.Recipients
If RecipientsName = "Sarah Bloggs" Or "Sarah Smith" Then
If InStr(LCase(Item.To), "Sarah Smith" Or "Sarah Weedon") Then
Prompt$ = "You sending this to " & Item.To & ". Is it the correct one?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End If
Else: Exit Sub
End If
End Sub
答案 0 :(得分:0)
假设您获取收件人姓名的代码正常运行:
不确定为什么你有两个if语句来检查内容。
但是,你需要使用这样的OR
:
If RecipientsName = "Sarah Bloggs" Or RecipientsName = "Sarah Smith" Then
你总是要写出完整的条件,如:
If value1 = value2 [AND/OR value3=valu4] ...
阅读有关VBA的更多信息,如果......那么......在msdn上的Else声明:https://msdn.microsoft.com/de-de/library/752y8abs.aspx
答案 1 :(得分:0)
在知道如何操作之前,请勿使用On Error代码。错误被隐藏,因此您无法修复错误。
{{1}}