|
Outlook2003,“规则和通知”中,
规则:带有附件
运行:脚本
功能:
当发件人邮件地址中含有"zhangsan"时,把附件保存到目录:"f:\outlook\attachment\张三\"
当发件人邮件地址中含有"lisi"时,把附件保存到目录:"f:\outlook\attachment\李四\"
否则,把附件保存到目录:"f:\outlook\attachment\未分组\"
脚本参考:
http://blog.ipodmp.com/archives/ ... y-save-attachments/
脚本:- Public Sub SaveAttach(Item As Outlook.MailItem)
- Dim RootPath, NewF, NewPath
-
- Select Case Item.SenderEmailAddress
-
- Case InStr(Item.SenderEmailAddress, "zhangsan") > 0
-
- RootPath = "f:\outlook\attachment\张三"
-
- Case InStr(Item.SenderEmailAddress, "lisi") > 0
-
- RootPath = "f:\outlook\attachment\李四"
-
- Case Else
-
- RootPath = "f:\outlook\attachment\未分组"
-
- End Select
-
-
- NewF = Date & "." & Item.Subject
- NewPath = RootPath & NewF & ""
- SaveAttachment Item, NewPath, "*.*"
- End Sub
-
- ' 保存附件函数
- ' path为保存路径,condition为附件名匹配条件
- Private Sub SaveAttachment(ByVal Item As Object, ByVal path As String, Optional condition = "*")
- Dim olAtt As Attachment
- Dim i As Integer
- '检查文件夹是否存在,不存在就新建
- Dim fso, f
- Set fso = CreateObject("Scripting.FileSystemObject")
- If fso.FolderExists(path) <> True Then
- fso.CreateFolder (path)
- End If
- '循环保存附件
- If Item.Attachments.Count > 0 Then
- For i = 1 To Item.Attachments.Count
- Set olAtt = Item.Attachments(i)
- If olAtt.FileName Like condition Then
- olAtt.SaveAsFile path & olAtt.FileName
- End If
- Next
- End If
- MsgBox "此次保存 " & Item.Attachments.Count & " 个对象."
- Set olAtt = Nothing
- End Sub
- '该函数自动补充不足的"0″
- Function RLeft(sval)
- RLeft = Right("00" & CStr(sval), 2)
- End Function
复制代码 运行结果:
全部附件都保存到了"f:\outlook\attachment\未分组\"目录。
求高手帮忙看看哪不对,谢谢! |
|