让outlook自动检查“空标题”和“空附件”
经常点完发送按钮后就叫起来,“啊呀,又忘了写主题了...”或者“完了,又把附件给漏了...”。给客户的感觉就是做事情不细心总是犯同样的错误。
发现一好文章,在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. 按“Alt + F11” 键来打开VB Script
c. 点击左侧树状目录最下面的“ThisOutlookSession”,看到右边出现空白的编辑窗口
d. 把(1)或(2)或(3)的代码拷贝到编辑窗口,保存,退出VB Script编辑。(不用重启Outlook)
就这么简单,自己写个email测试一下功能看看?能否看到提示窗口?
经过测试,在Outlook 2002/2003上通过。
对于“Missing Attachment”功能,补充两句:这段代码是检查Email正文中的关键词:attach, enclose,来判断是否要求添加附件。根据自己需要,可以添加关键词,比如“附件”等等。代码中有:
Dim sSearchStrings(1) As String
和
sSearchStrings(0) = "attach"
sSearchStrings(1) = "enclose"
如果要增加关键词,就相应增加sSearchStrings(1)中的数字(如果有N个关键词,就为N-1),然后在下面添加相应的关键词,如:
sSearchStrings(2) = "附件"
说干就干,先把这两个别人写的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. 按“Alt + F11” 键来打开VB Script
c. 点击左侧树状目录最下面的“ThisOutlookSession”,看到右边出现空白的编辑窗口
d. 把(1)或(2)或(3)的代码拷贝到编辑窗口,保存,退出VB Script编辑。(不用重启Outlook)
就这么简单,自己写个email测试一下功能看看?能否看到提示窗口?
经过测试,在Outlook 2002/2003上通过。
对于“Missing Attachment”功能,补充两句:这段代码是检查Email正文中的关键词:attach, enclose,来判断是否要求添加附件。根据自己需要,可以添加关键词,比如“附件”等等。代码中有:
Dim sSearchStrings(1) As String
和
sSearchStrings(0) = "attach"
sSearchStrings(1) = "enclose"
如果要增加关键词,就相应增加sSearchStrings(1)中的数字(如果有N个关键词,就为N-1),然后在下面添加相应的关键词,如:
sSearchStrings(2) = "附件"
posted on 2007-12-25 11:25 littlebamboo 阅读(1790) 评论(1) 编辑 收藏 举报