【发布时间】:2015-09-17 17:23:43
【问题描述】:
当我关闭并重新启动 Outlook 时,宏不起作用。
此代码将在 Outlook 中发送邮件的主题和附件之前进行验证。
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim lngAns As Long
Dim varArray As Variant
Dim strWordFound As String
varArray = Array("PFA", "Attached", "Enclosed", "File", "Report")
For lngCount = LBound(varArray) To UBound(varArray)
If InStr(1, Item.Body, varArray(lngCount), vbTextCompare) Or InStr(1, Item.Subject, varArray(lngCount), vbTextCompare) Then
strWordFound = strWordFound & "," & varArray(lngCount)
End If
Next
strWordFound = Mid(strWordFound, 2)
If Len(strWordFound) > 0 And Item.Attachments.Count = 0 Then
If MsgBox("Found No Attachments but the Word(s): " & _
strWordFound & vbTab & vbCr & "Do you want to send the mail anyway?", _
vbYesNo + vbQuestion, "Attachment Missing") = vbNo Then Cancel = True
End If
If Len(Trim(Item.Subject)) = 0 Then
If MsgBox("Subject is Empty. Are you sure you want to send the Mail?", _
vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Subject Missing") = vbNo Then Cancel = True
End If
End Sub
【问题讨论】:
-
此代码无法在启动时运行。既然您知道“此代码将在发送邮件之前进行验证”,那么关于在发送邮件之前代码未运行的问题。
-
当我保存代码然后尝试发送没有任何主题或附件的邮件时。有用。如果我关闭 Outlook 应用程序,然后撰写邮件并发送没有任何主题行或附件的电子邮件。此代码不起作用。这就是挑战。如果可以,请提供帮助。