【发布时间】:2015-03-09 14:03:09
【问题描述】:
计划: Outlook 2010
要求:
在约会触发器触发时发送电子邮件。将使用超过 1 个类别。
问题:
日历显示 VBA 代码第二部分的正确类别,但是当电子邮件触发时,它会恢复到第一类别并使用这些参数发送。代码如下:
Private Sub Application_Reminder(ByVal Item As Object)
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
If Item.MessageClass <> "IPM.Appointment" Then
Exit Sub
End If
If Item.Categories <> "Cat - Test (1)" Then
objMsg.To = Item.Location
objMsg.Subject = Item.Subject & " | " & Format(Now, "YYYYMMDD")
objMsg.HTMLBody = Format(Now, "Long Date") & Item.Body
objMsg.CC = "email"
objMsg.BCC = "email 1, 2, 3"
objMsg.Categories = "Cat - Test (1)"
objMsg.Send
'this is the code that reverts to the one above at the time of sending, _
'but looks as it should in the calendar preview.
ElseIf Item.Categories <> "Cat - Test (2)" Then
objMsg.To = Item.Location
objMsg.Subject = Item.Subject & " | " & Format(Now, "YYYYMMDD")
objMsg.HTMLBody = Format(Now, "Long Date") & Item.Body
objMsg.CC = "email"
objMsg.BCC = "emails"
objMsg.Categories = "Cat - Test (2)"
objMsg.Send
Else
Exit Sub
End If
Set objMsg = Nothing
End Sub
任何建议,似乎我可能缺少某种结束,或者使用 IF / elseIF 的正确方法我尝试添加和省略一些 IF、ElseIF,但我无法让它正确触发.
我还创建了一个没有类别的日历约会,但在“位置”字段中有一封电子邮件,它仍然会触发宏运行。
提前谢谢你。
【问题讨论】:
-
查看您的代码,如果
Item.Categories的值为“Cat - Test (2)”,那么您将设置objMsg.Categories为“Cat - Test (1)”。这是你的意图吗?如果没有,请尝试在 if/elseif 语句中将<>替换为=。 -
@GrahamAnderson 谢谢你,这就是我的回答。如果您将其写为答案,我可以为您标记。太棒了!
-
不客气,已作为答案发布。