当我关闭并重新启动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