避免outlook发信,忘记标题和附件

来源:互联网 发布:修改文件权限linux 编辑:程序博客网 时间:2024/06/02 05:07

在outlook 2003中添加“空邮件标题”和“空附件”检查功能

 

 

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)If TypeName(Item) <> "MailItem" Then Exit SubDim cancel_Subject As BooleanDim cancel_Attach As Boolean'CHECK FOR BLANK SUBJECT LINEIf Item.Subject = "" Thencancel_Subject = MsgBox("这个邮件没有主题." & vbNewLine & _"你确认要发送吗?", _vbYesNo + vbExclamation, "空主题") = vbNoEnd IfIf cancel_Subject = False Then'CHECK FOR FORGETTING ATTACHMENTDim intRes As IntegerDim strMsg As StringDim strThismsg As StringDim intOldmsgstart As Integer' ADDED BY LS >>>' - Does not search for "Attach", but for all strings in an array that is defined hereDim sSearchStrings(1) As StringDim bFoundSearchstring As BooleanDim i As Integer ' loop var for FOR-NEXT-loopbFoundSearchstring = FalsesSearchStrings(0) = "附件"sSearchStrings(1) = "文档"' ADDED BY LS <<<intOldmsgstart = InStr(Item.Body, "本邮件及其附件含有华为公司的保密信息,仅限于发送给上面地址中列出的个人或群组。")' intOldmsgstart is the location of where old/re/fwd/signature msg starts. Will be 0 if new msgIf intOldmsgstart = 0 ThenstrThismsg = Item.Body + " " + Item.SubjectElsestrThismsg = Left(Item.Body, intOldmsgstart) + " " + Item.SubjectEnd 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 ThenbFoundSearchstring = TrueExit ForEnd IfNext i' ADDED BY LS <<<If bFoundSearchstring ThenIf Item.Attachments.Count = 0 ThenstrMsg = "附件检查:" & Chr(13) & Chr(10) & "你的邮件中提到附件, 但是你还没有上传附件." & Chr(13) & Chr(10) & "你确认要发送吗?"intRes = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbExclamation, "你忘记上传附件啦!")If intRes = vbNo Then' cancel sendcancel_Attach = TrueEnd IfEnd IfEnd IfEnd IfIf (cancel_Subject Or cancel_Attach) = True ThenCancel = TrueEnd IfEnd Sub


 

下面来简单介绍怎么用,或者说怎么嵌入到outlook中:
a. 打开outlook
b. 按“Alt + F11” 键来打开VB Script
c. 点击左侧树状目录最下面的“ThisOutlookSession”,看到右边出现空白的编辑窗口
d. 把代码拷贝到编辑窗口,保存,退出VB Script编辑。(不用重启Outlook)

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

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

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

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

 

原创粉丝点击