ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1569|回复: 0

[求助] Outlook2010 发送附件检查

[复制链接]

TA的精华主题

TA的得分主题

发表于 2013-3-25 09:36 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
下代码不能正常检查,请高手帮助看看,谢谢~~
Private Declare Function MsgBoxEx Lib "user32" Alias "MessageBoxTimeoutA" ( _
    ByVal hwnd As Long, _
    ByVal lpText As String, _
    ByVal lpCaption As String, _
    ByVal wType As VbMsgBoxStyle, _
    ByVal wlange As Long, _
    ByVal dwTimeout As Long) As Long
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeName(Item) <> "MailItem" Then Exit Sub
Dim intRes As Integer
Dim strMsg As String
Dim strThismsg As String
Dim intOldmsgstart As Integer
Dim sSearchStrings(2) As String
Dim bFoundSearchstring As Boolean
Dim i As Integer ' loop var for FOR-NEXT-loop
Dim intDeferStyle As Integer
Dim intDeferTime As Integer
Dim intMailImportance As Integer
Dim bDeferImportance As Boolean
bFoundSearchstring = False
intMailImportance = Item.Importance
'设定附件提醒的相关参数
sSearchStrings(0) = "attach" '正文或标题包含的关键字,当找到这些关键字时,就认定邮件应该带附件
sSearchStrings(1) = "enclose" '可以设定多个关键字,但记得在“Dim sSearchStrings(2) As String”语句中更改数组上限
sSearchStrings(2) = "附件"
'延时发送相关参数,可以更改
intDeferStyle = 1 '延时发送的模式,0=不延时发送,1=跳出倒计时对话框,2=采用outlook自带的延时发送属性DeferredDeliveryTime
intDeferTime = 10 '延时发送的时间,单位秒
bDeferImportance = False '重要性为高的邮件是否也延时发送,0=重要性高的邮件不延时,1=重要性高的邮件也延时
If bDeferImportance Then
    intMailImportance = 1
End If
'检查附件
intOldmsgstart = InStr(Item.Body, "-----Original Message-----")
If intOldmsgstart = 0 Then
    strThismsg = Item.Body + " " + Item.Subject
Else
    strThismsg = Left(Item.Body, intOldmsgstart) + " " + Item.Subject
End If
For i = LBound(sSearchStrings) To UBound(sSearchStrings)
    If InStr(LCase(strThismsg), sSearchStrings(i)) > 0 Then
        bFoundSearchstring = True
        Exit For
    End If
Next i
If bFoundSearchstring Then
    If Item.Attachments.Count = 0 Then
        strMsg = "Attachment Checker:" & Chr(13) & Chr(10) & "邮件内容提到了附件,但没有找到任何附件!" & Chr(13) & Chr(10) & "确定不添加附件吗?"
        intRes = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbExclamation, "You forgot the attachment!")
        If intRes = vbNo Then
            ' cancel send
            Cancel = True
        End If
    End If
End If
'延时发送
If intDeferStyle = 1 And intMailImportance <> 2 Then
    '弹出倒计时对话框的方式,实现延时发送
    strMsg = intDeferTime & "秒后发送邮件" & Chr(13) & Chr(10) & "马上发送请点确定,后悔请点取消,否则耐心等待"
    intRes = MsgBoxEx(0, strMsg, "延时发送邮件", vbYesNo + vbInformation, 1, intDeferTime * 1000)
    If intRes = vbNo Then
        Cancel = True
    End If
ElseIf intDeferStyle = 2 And intMailImportance <> 2 Then
    '采用outlook自带的DeferredDeliveryTime属性实现延时发送,有些小问题,很难控制10秒后准确发送,请高手解决,菜鸟可以用第一种延时发送方式
    Item.DeferredDeliveryTime = DateAdd("s", intDeferTime, Now)
   
End If
End Sub
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2025-1-9 03:14 , Processed in 0.017700 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表