|
本帖最后由 sunw1984 于 2017-11-10 16:00 编辑
各位高手
本人新手一枚,从论坛找到和学习了批量下载指定文件夹附件,非常方便实用,但是现在又遇见新的问题,比如我的Outlook客户端又新绑定了一个账户DEF@XXX.COM (假定原存在账户为ABC@XXX.COM), 请问如何修改以下代码,使得其能够下载指定新增的账户DEF@XXX.COM 下B文件夹内所有附件
非常感谢不吝赐教
以下是源代码,客户端新增了一个账户后,一运行就卡死- Sub downloadatt()
- On Error Resume Next
- Dim olApp As New Outlook.Application
- Dim nmsName As Outlook.NameSpace
- Dim vItem As Object
- Set nmsName = olApp.GetNamespace("MAPI")
- Set myFolder = nmsName.GetDefaultFolder(olFolderInbox)
- Set fldFolder = myFolder.Folders("M")
-
- For Each vItem In fldFolder.Items
-
- MyArray = Split(Attachment.DisplayName, ".", -1, 1)
- strname = MyArray(0) & Format(mymailitem.CreationTime, "_yyyymmdd_hhnnss") & "." & MyArray(1)
- strname = MyArray(0) & Format(mymailitem.ReceivedTime, "_yyyymmdd_hhnn") & "." & MyArray(1)
- strname = Right(MyArray(0), InStr(MyArray(0), "G1m")) & "." & MyArray(1)
- If (fso.FileExists(filefolder & strname) = False) Then
- temp = i & " " & mymailitem.Subject & " " & mymailitem.CreationTime & " " & Attachment.DisplayName
- Attachment.SaveAsFile filefolder & strname
- temp = mymailitem.CreationTime & " " & filefolder & strname
- f.Writeline temp
-
- msg = msg & temp & vbCrLf
- wcount = wcount + 1
- End If
-
- For Each att In vItem.Attachments
-
- fn = "C:\Users\W\Documents\8. Report" & att.FileName
- Do Until Dir(fn) = ""
- fn = "C:\Users\W\Documents\8.Report" & n & att.FileName
- n = n + 1
- Loop
- att.SaveAsFile fn
- Next
-
- Next
-
- Set fldFolder = Nothing
- Set nmsName = Nothing
- End Sub
复制代码
|
|