设为首页 收藏本站
查看: 967|回复: 0

[经验分享] 让outlook自动检查“空标题”和“空附件”

[复制链接]

尚未签到

发表于 2015-9-12 13:40:29 | 显示全部楼层 |阅读模式
     经常点完发送按钮后就叫起来,“啊呀,又忘了写主题了...”或者“完了,又把附件给漏了...”。给客户的感觉就是做事情不细心总是犯同样的错误。
     发现一好文章,在outlook 2003中添加“空邮件标题”和“空附件”检查功能。自己实践过了,好用!
   以下文章转自http://hi.baidu.com/%CA%AB%D5%B9/blog/item/c7f8dff9d032d658242df275.html,转载请注明出处。

如何避免outlook发信,忘记标题和附件
在outlook 2003中添加“空邮件标题”和“空附件”检查功能

最近经常发现发Email的时候忘记写邮件标题或遗漏附件,于是在网上搜索相关检查工具。有幸,找到了两个,一个是专门检查“空标题”的,另外一个是检查”遗漏附件“。可是发现无法在outlook 2003中将这两个VB script加进去,于是乎,想到一个办法:为何不能吧这两个检查合并为一个检查呢?

说干就干,先把这两个别人写的VB script抄下来参考(1)和(2),然后将其合并为(3),主要修改的是关于Cancel的赋值和判断,增加了两个布尔变量(cancel_Subject , cancel_Attach)来保存两个弹出窗口的判断值:

1)Blank Subject

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeName(Item) <> "MailItem" Then Exit Sub

'CHECK FOR BLANK SUBJECT LINE
If Item.Subject = "" Then
Cancel = MsgBox("This message does not have a subject." & vbNewLine & _
"Do you wish to continue sending anyway?", _
vbYesNo + vbExclamation, "No Subject") = vbNo
End If
End Sub

2)Missing Attachment

' VBA program for Outlook, (c) Dan Evans. dan at danevans.co.uk
' Will check if your outgoing email mentions an attachment, but you've
' forgotten to attach it

' v1.03b of 29/7/05 - Modified by Leonard Slingerland (leonard at slingerland.biz) to have array of words rather than just one
' v1.03 of 10/8/04 - Modified to search through subject line as well as message body
' v1.02 of 16/10/02 - No change to code, but tested works with Outlook 2002 as well as Outlook 2000
' v1.01 of 23/9/01 - OK for "Attach" as well as "attach"
' v1.00 of 21/9/01 - Initial working version

Dim intRes As Integer
Dim strMsg As String
Dim strThismsg As String
Dim intOldmsgstart As Integer

' ADDED BY LS >>>
' - Does not search for "Attach", but for all strings in an array that is defined here
Dim sSearchStrings(3) As String
Dim bFoundSearchstring As Boolean
Dim i As Integer ' loop var for FOR-NEXT-loop
bFoundSearchstring = False

sSearchStrings(0) = "attach"
sSearchStrings(1) = "hereby"
sSearchStrings(2) = "bijlage" ' Dutch
sSearchStrings(3) = "hierbij" ' Dutch
' ADDED BY LS <<<

intOldmsgstart = InStr(Item.Body, "-----Original Message-----")
' intOldmsgstart is the location of where old/re/fwd msg starts. Will be 0 if new msg

If intOldmsgstart = 0 Then
strThismsg = Item.Body + " " + Item.Subject
Else
strThismsg = Left(Item.Body, intOldmsgstart) + " " + Item.Subject
End If
' The above if/then/else will set strThismsg to be the text of this message only,
' excluding old/fwd/re msg
' IE if the original included message is mentioning an attachment, ignore that
' Also includes the subject line at the end of the strThismsg string

' ADDED BY LS >>>
For i = LBound(sSearchStrings) To UBound(sSearchStrings)
If InStr(LCase(strThismsg), sSearchStrings(i)) > 0 Then
bFoundSearchstring = True
Exit For
End If
Next i
' ADDED BY LS <<<

If bFoundSearchstring Then
If Item.Attachments.Count = 0 Then
strMsg = "Dan Evans' Attachment Checker:" & Chr(13) & Chr(10) & "Your message mentions an attachment, but doesn't have one." & Chr(13) & Chr(10) & "Send the message anyway?"
intRes = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbExclamation, "You forgot the attachment!")
If intRes = vbNo Then
' cancel send
Cancel = True
End If
End If
End If

3)Blank Subject & Missing Attachment

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeName(Item) <> "MailItem" Then Exit Sub

Dim cancel_Subject As Boolean
Dim cancel_Attach As Boolean


'CHECK FOR BLANK SUBJECT LINE
If Item.Subject = "" Then
cancel_Subject = MsgBox("This message does not have a subject." & vbNewLine & _
"Do you wish to continue sending anyway?", _
vbYesNo + vbExclamation, "No Subject") = vbNo
End If

'CHECK FOR FORGETTING ATTACHMENT
Dim intRes As Integer
Dim strMsg As String
Dim strThismsg As String
Dim intOldmsgstart As Integer

' ADDED BY LS >>>
' - Does not search for "Attach", but for all strings in an array that is defined here
Dim sSearchStrings(1) As String
Dim bFoundSearchstring As Boolean
Dim i As Integer ' loop var for FOR-NEXT-loop
bFoundSearchstring = False

sSearchStrings(0) = "attach"
sSearchStrings(1) = "enclose"

' ADDED BY LS <<<

intOldmsgstart = InStr(Item.Body, "-----Original Message-----")
' intOldmsgstart is the location of where old/re/fwd msg starts. Will be 0 if new msg

If intOldmsgstart = 0 Then
strThismsg = Item.Body + " " + Item.Subject
Else
strThismsg = Left(Item.Body, intOldmsgstart) + " " + Item.Subject
End If
' The above if/then/else will set strThismsg to be the text of this message only,
' excluding old/fwd/re msg
' IE if the original included message is mentioning an attachment, ignore that
' Also includes the subject line at the end of the strThismsg string

' ADDED BY LS >>>
For i = LBound(sSearchStrings) To UBound(sSearchStrings)
If InStr(LCase(strThismsg), sSearchStrings(i)) > 0 Then
bFoundSearchstring = True
Exit For
End If
Next i
' ADDED BY LS <<<

If bFoundSearchstring Then
If Item.Attachments.Count = 0 Then
strMsg = "Attachment Checker:" & Chr(13) & Chr(10) & "Your message mentions an attachment, but doesn't have one." & Chr(13) & Chr(10) & "Send the message anyway?"
intRes = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbExclamation, "You forgot the attachment!")
If intRes = vbNo Then
' cancel send
cancel_Attach = True
End If
End If
End If

If (cancel_Subject Or cancel_Attach) = True Then
Cancel = True
End If

End Sub


----------------------
如何使用它呢,你可以选择(1)或(2)满足自己的需要,或者用(3)来使用两种检查功能。下面来简单介绍怎么用,或者说怎么嵌入到outlook 2003中:
a. 打开outlook
b. 按&#8220;Alt + F11&#8221; 键来打开VB Script
c. 点击左侧树状目录最下面的&#8220;ThisOutlookSession&#8221;,看到右边出现空白的编辑窗口
d. 把(1)或(2)或(3)的代码拷贝到编辑窗口,保存,退出VB Script编辑。(不用重启Outlook)

就这么简单,自己写个email测试一下功能看看?能否看到提示窗口?

经过测试,在Outlook 2002/2003上通过。

对于&#8220;Missing Attachment&#8221;功能,补充两句:这段代码是检查Email正文中的关键词:attach, enclose,来判断是否要求添加附件。根据自己需要,可以添加关键词,比如&#8220;附件&#8221;等等。代码中有:
Dim sSearchStrings(1) As String

sSearchStrings(0) = "attach"
sSearchStrings(1) = "enclose"
如果要增加关键词,就相应增加sSearchStrings(1)中的数字(如果有N个关键词,就为N-1),然后在下面添加相应的关键词,如:
sSearchStrings(2) = "附件"

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-112708-1-1.html 上篇帖子: Outlook 2013 中添加 live.cn 帐户 下篇帖子: 通过Visual studio 2005 中的web.sitemap实现OUTLOOK风格的系统菜单
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

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