我使用VBA发送电子邮件。每封电子邮件都会弹出一个分类,需要手动设置。我正在尝试在代码中解决这个问题。
我找到了一个发送电子邮件的代码:Mail a message with outlook via VBA。
在修复了一些东西之后,下面的代码就可以正常工作了。
Sub sendEmail()
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Working in Office 2000-2016
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Application.EnableEvents = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Dear " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"Please Finish your course " & Cells(cell.Row, "C") & _
" before expiry date."
.Send 'Or use Display
End With
On Error GoTo 0
Set OutMail = Nothing
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
问题是,在从列表中向例如10个人发送电子邮件后,我需要单击10次分类弹出窗口。
我发现了这个:How to save workbook and handle TITUS (or any other document classification add-in) popup?
我在.Send
之前尝试过.EnableEvents = False
。我不确定这对我是否有用。
如何在我的案例中使用它?是否可以禁用它,解决它,甚至在代码中设置一个分类?
发布于 2018-12-20 03:32:25
有一种解决方法,但您必须在Outlook Developer本身中执行此操作。您可以在Outlook中设置触发宏的事件处理程序。因此,在这种情况下,Outlook可以监视使用特定主题行(例如)创建的邮件,这将触发下面的脚本,从而绕过TITUS。
'Sets Titus Mail settings and sends mail
With AOMailMsg
objMsg.ItemProperties.Add("ABCDE.Registered To", olText) = "My Companies"
objMsg.ItemProperties.Add("ABCDE.Classification", olText) = "Internal"
objMsg.UserProperties.Add("ABCDE.Registered To", olText) = "My Companies"
objMsg.UserProperties.Add("ABCDE.Classification", olText) = "Internal"
objMsg.UserProperties.Add("TITUSAutomatedClassification", olText) = _
"TLPropertyRoot=ABCDE;.Registered To=My Companies;.Classification=Internal;"
objMsg.Send
End With
https://stackoverflow.com/questions/49128979
复制相似问题