VBA检查发送邮件附件

  最近发邮件老是忘记发送邮件附件,自己写了个vba小程序进行检查,如果title(主题)包含特定字符串,比如公司要求的leave request,time sheet就会进行检查并提示。感觉挺好用。代码和步骤如下。

  1.  打开outlook
  2.  ALT+F11 进入代码编辑模式
  3. 在模块ThisOutlookSession中添加代码并保存即可
  图片为截图



代码如下:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    'Pops up a reminder if the word "attach?± is found but there is no attachment on your email.
Dim m As Variant
Dim strBody As String
Dim intIn As Long
Dim intAttachCount As Integer, intStandardAttachCount As Integer
Dim strTitle As String
Dim arrLen As Integer
  'title检查文本
checkStr = Array("leave request", "expense sheet", "timesheet", "time sheet", "attach")

Dim hasAtt As Boolean


On Error GoTo handleError
intStandardAttachCount = 1

'for title check
strTitle = LCase(Item.Subject)
    
arrLen = UBound(checkStr)
For i = 0 To arrLen
    intIn = InStr(1, strTitle, checkStr(i))
    If intIn > 0 Then hasAtt = True
    intIn = 0
Next i
    
If hasAtt = True Then
    m = MsgBox("你又忘记附件了!" & vbCrLf & "there is no attachment to this message." & vbCrLf & vbCrLf & "Do you still want to send?", vbQuestion + vbYesNo + vbMsgBoxSetForeground)

If m = vbNo Then Cancel = True

End If

handleError:

If Err.Number <> 0 Then
    MsgBox "Outlook Attachment Reminder Error: " & Err.Description, vbExclamation, "Outlook Attachment Reminder Error"
End If
End Sub

也可以添加别的检查,看自己的需求了。
参考文章:http://www.businesshut.com/outlook-macros/outlook-attachment-reminder-macro/ 。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值