一、前言

仅做一下记录,放置后边不好找

二、代码

  1. Public Sub SaveAttach(Item As Outlook.MailItem)
  2. 'MsgBox (Item.Subject)
  3. ReceivedTime = Format(Item.ReceivedTime, "yyyymmdd")
  4. FilePath = "d:\WorkFiles\" + Format(Item.ReceivedTime, "yyyy") + "\" + Format(Item.ReceivedTime, "mm") + "\" + ReceivedTime + "-秎ンン-" + Item.Subject
  5. 'MsgBox (FilePath)
  6. Dim hasPath
  7. hasPath = dir(FilePath, vbDirectory)
  8. If hasPath = "" Then
  9. MkDir (FilePath)
  10. Else
  11. FilePath = FilePath + "_" + Format(Now, "hhmmss")
  12. MkDir (FilePath)
  13. End If
  14. 'MsgBox FilePath
  15. 'MkDir FilePath
  16. SaveAttachment Item, FilePath + "\"
  17. MsgBox "玂秎ン" + Item.Subject + "" + "いン"
  18. End Sub
  19. '保存附件
  20. ' path为保存路径,condition为附件名匹配条件
  21. Private Sub SaveAttachment(ByVal Item As Object, path$, Optional condition$ = "*")
  22. Dim olAtt As Attachment
  23. Dim i As Integer
  24. If Item.Attachments.Count > 0 Then
  25. For i = 1 To Item.Attachments.Count
  26. Set olAtt = Item.Attachments(i)
  27. ' save the attachment
  28. If olAtt.FileName Like condition Then
  29. olAtt.SaveAsFile path & olAtt.FileName
  30. End If
  31. Next
  32. End If
  33. Set olAtt = Nothing
  34. End Sub

三、调用

通过添加规则对所有收到的携带附件的邮件运行以上脚本即可。


如果你喜欢我的文章,欢迎来给我买咖啡,而且还可以买不止一杯。
1648650243435.png1648650243428.jpg
捐赠支持作者!