|
本帖最后由 闻启学 于 2013-12-24 09:22 编辑
求缺妞嫁我 发表于 2013-12-24 09:11
我是小白啊。。。。。。我不知道你写的那句加到我程序的哪里?能否看一下你的完整的程序?
厉害 小白都可以用类来做- Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
- '//收到邮件后 附件自动保存到指定的路径
- Dim varEntryIDs
- Dim objItem As Outlook.MailItem
- Dim i As Integer
- Set objItem = Application.Session.GetItemFromID(EntryIDCollection) '//根据ID号 获得整个邮件
- Call NewMail.NewMailSaveAttachemnets(objItem) '//附件的处理
- End Sub
复制代码
- Sub NewMailSaveAttachemnets(myMail As Outlook.MailItem)
- '// outlook 收到新邮件是 将邮件的附件 自动放到指定位置
- On Error Resume Next
- Dim mail As Outlook.MailItem
- Dim Fso As Object
- Dim myOlExp As Outlook.Explorer '//outlook
- Dim myOlSel As Outlook.Selection '//outlook所在选择项
- Set Fso = CreateObject("Scripting.FileSystemObject") '//FSO文件对象
- Dim MsgTxt As String
- Dim x As Integer
- Dim Folder As String
- Dim reg As String
- Dim MyFileName As String
- Set myOlExp = Application.ActiveExplorer '//指向对象 outlook
- Dim vItem As Outlook.Attachment
- reg = "\d+" '//正则表达式
- If myMail.Attachments.Count > 0 Then
- For i = 1 To myMail.Attachments.Count
- Set vItem = myMail.Attachments(i)
- MyFileName = myMail.Subject
- If InStr(MyFileName, "单") = 0 Then '//判断邮件主题 是包含 “单”
- vItem.SaveAsFile "D:" & vItem.FileName '//保存到另外一个文件夹
- Else
- If InStr(Split(vItem.FileName, ".")(1), "pdf") > 0 Then
- '//判断是否包含该月份的文件夹,有则保存在文件夹 ,无则创建文件
- Folder = "D:\PDF文件\2013" & Val(Mid(getRegtoString(reg, MyFileName), 5, 2)) & "月份" '//判断月份
- If Not Fso.FolderExists("Folder") Then '//无则创建文件夹
- Fso.CreateFolder (Folder)
- End If
- vItem.SaveAsFile Folder & "" & vItem.FileName '//保存附件路径
- Else
- vItem.SaveAsFile "D:\PDF文件\2013" & vItem.FileName '//保存到根目录文件夹
- End If
- End If
- Next i
- End If
- End Sub
复制代码 |
|