|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
报错如图片所示,画圈那行代码,那个getRegtoString(reg, MyFileName), 5, 2),这个函数报错未定义,这个不是vba提供的函数吗?完整代码如下,
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
'//收到邮件后 附件自动保存到指定的路径
Dim varEntryIDs
Dim objItem As Outlook.MailItem
Dim i As Integer
varEntryIDs = Split(EntryIDCollection, ",") '//获得邮件的ID号 唯一的
For i = 0 To UBound(varEntryIDs)
Set objItem = Application.Session.GetItemFromID(varEntryIDs(i)) '//根据ID号 获得整个邮件
Call NewMailSaveAttachements(objItem) '//附件的处理
Next
'// MsgBox "你共收到" & UBound(varEntryIDs) & "邮件 "
End Sub
Sub NewMailSaveAttachements(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
Dim myT1, myT2, myT3, myT As String
Set myOlExp = Application.ActiveExplorer '//指向对象 outlook
'// Set myOlSel = myOlExp.Selection
Dim vItem As Outlook.Attachment
reg = "\d+" '//正则表达式
If myMail.Attachments.Count > 0 Then
For i = 1 To myMail.Attachments.Count
myT1 = CStr(Format(myMail.SentOn, "yyyymmdd"))
myT2 = myMail.SenderName
Set vItem = myMail.Attachments(i)
MyFileName = vItem.FileName
myT = path0 & "\" & myT1 & "-" & myT2 & "-" & MyFileName
'//Debug.Print MyFileName
If InStr(MyFileName, "思考A3") = 0 Or InStr(MyFileName, "广发纳斯特乐睿1号") = 0 Then
'//判断是否包含该月份的文件夹,有则保存在文件夹 ,无则创建文件
Folder = "E:\outlook\" & 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 "E:+\outlook\down\" & vItem.FileName '//保存到根目录文件夹
End If
Next i
End If
End Sub
有人可以帮我改为正确的吗,谢谢!
|
-
报错图片
|