发送电子邮件时如何检查附件? [英] How to check for attachment when sending an email?
问题描述
我遇到了一些宏,这些宏检查当您在电子邮件中使用单词"attachment"(或您想要的其他任何单词)时是否附加了任何项目,例如以下:
I've come across macros that check whether any items are attached when you use the word 'attachment' (or any other word you desire) in your email, e.g. the following:
Public Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim vList As Variant
Dim answer As Integer
Dim i As Integer
vList = Array("attached", "attachment")
If Item.Attachments.Count = 0 Then
For i = 0 To UBound(vList)
If InStr(1, LCase(Item.Body), LCase(vList(i)), vbTextCompare) > 0 Then
answer = MsgBox("There's no attachment, send anayway?", vbYesNo)
If answer = vbNo Then Cancel = True
Exit Sub
End If
Next i
End If
End Sub
我只看过检查 Item.Body
是否包含指定单词之一的宏.回复电子邮件时, Item.Body
不仅是新文本,而且还是我要回复的以前的文本.
这是一个问题,因为许多客户的免责声明中都带有"attachment"一词.结果,我经常收到警告,在不必要的时刻没有附件.
I've only seen macros that check whether the Item.Body
contains one of the specified words. When responding to an email, Item.Body
is not just the new text, but also the previous text to which I am responding.
This is a problem, as many clients have the word 'attachment' in their disclaimer. As a result, I often get the warning that there is no attachment at unnecessary moments.
我尝试了 Item
对象的不同属性.
I tried different properties of the Item
object.
在我看来,没有办法只选择最新输入的文本.
It seems to me there is no way to select only the newest typed text.
推荐答案
Private WithEvents OUT As Outlook.Application
Private lngAttachmentsOnOpen
Private Sub OUT_ItemLoad(ByVal Item As Object)
lngAttachmentsOnOpen = AttachmentMentionedXTimes(item.body) ' <---- count here
End Sub
Private Sub OUT_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim lngAttachmentsOnSend As Long
lngAttachmentsOnSend = AttachmentMentionedXTimes(item.body)' <--- count here
If lngAttachmentsOnSend > lngAttachmentsOnOpen Then
MsgBox "This code has been done for me due to my idleness :)"
End If
End Sub
Function AttachmentMentionedXTimes(ByVal strInput As String) As Integer
Dim a() As String
On Error GoTo eHandle
a = Split(strInput, "attachment", , vbTextCompare)
AttachmentMentionedXTimes = UBound(a)
Exit Function
eHandle:
AttachmentMentionedXTimes = 0
End Function
这篇关于发送电子邮件时如何检查附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!