【发布时间】:2016-01-05 06:22:14
【问题描述】:
我正在创建一个 Outlook 宏以在发送邮件之前验证电子邮件附件和收件人姓名。
可以通过 Outlook 会话中的 ItemSend 功能轻松验证收件人姓名。
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim Recipients As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim i
Dim prompt As String
Set Recipients = Item.Recipients
For i = Recipients.Count To 1 Step -1
Set recip = Recipients.Item(i)
If InStr(LCase(recip), "bad@address.com") Then
prompt$ = "You sending this to this to " & Item.To & ". Are you sure you want to send it?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End If
Next i
End Sub
虽然这有助于收件人,但它不允许在发送邮件之前验证附件名称。即验证邮件草稿。下面的代码有助于检查草稿中的附件,但无助于验证。
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then
If Item.Attachments.Count = 0 Then
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True
End If
所以我尝试添加 item.Attachment。名称 \ item.attachment.FileName 但这仅在我将其归因于 Outlook MailItem 而不是普通对象时才有效。
是否可以创建代码来验证特定标准的附件名称(名称应符合特定命名约束)。代码已经创建并作为普通宏而不是会话宏。
Function Segregate_Function(Attach_Name_Pass1 As String)
Dim FullName As String
Dim Recepients As String
Region_Ext = Right(Attach_Name_Pass1, 7)
region = Left(Region_Ext, 3)
'MsgBox region
If region = "ENG" Then
Recepients = "ABC@gmail.com;XYZ@gmail.com"
Call Send_Function(Attach_Name_Pass1, Recepients)
Else
MsgBox " Not an Acceptable Attachment. Mail Could not be Generated "
End If
End Function
我希望在单击发送以直接验证附件名称时执行上述代码,而不是运行程序宏。
做建议。
【问题讨论】: