|
我用的outlook2010,outlook规则里面的延迟发送邮件,最小间隔是1分钟,这个有点长,有时候碰到比较急的邮件,要等1分钟才发出去实在是太急人了。个人认为10秒的延迟发送也就足够了,肯定来得及后悔。所以想用vba做一个。
看了之前的帖子,试着用这个语句来延迟发送,在当前时间基础上延迟10秒:
item.DeferredDeliveryTime=DateAdd("s",10,now())
但发现实际效果不如人意,这个DeferredDeliveryTime总是自动取整的分钟数。比如现在是10:50:20,那么DateAdd("s",10,now)之后应该是10:50:30,但实际上,如果msgbox item.DeferredDeliveryTime电话,会发现这个DeferredDeliveryTime被设定成10:51:00,后面这个秒数总是自动取0。
求高手解决。另外我想的另外一个方法,直接在写完邮件点击发送按钮之后,出现一个10秒倒计时的对话框,如果倒计时为0就开始发送,如果中途点击了“取消”,就取消发送。不过,用msgbox好像不能显示倒计时,也不能自动关闭,我的vba知识很少,不知道该用什么方法,求助。
另外,分享一个个人觉得比较好的检查附件的vba,从网上查到的,感谢原作者。这个vba的优点在于:可以自己设定检查的关键字。记得把outlook的宏安全设定为“低”:
- Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
- If TypeName(Item) <> "MailItem" Then Exit Sub
- ' 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(2) As String
- Dim bFoundSearchstring As Boolean
- Dim i As Integer ' loop var for FOR-NEXT-loop
- bFoundSearchstring = False
- sSearchStrings(0) = "attach"
- sSearchStrings(1) = "enclose"
- sSearchStrings(2) = "附件"
- ' 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) & "邮件内容提到了附件,但没有找到任何附件!" & 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
- End Sub
复制代码
|
|