![](/img/trans.png)
[英]vba script to save all attachments (PDFs) from outlook then delete the emails
[英]Save all outlook attachments
我想保存 Outlook 365 收件箱中的所有附件。
復制本教程我寫道:
Sub Download_Attachments()
Dim ns As NameSpace
Dim olFolder_Inbox As Folder
Dim olMail As MailItem
Dim olAttachment As Attachment
Dim fso As Object
Dim File_Saved_Folder As String
File_Saved_Folder_Path = "C:\GIS\temp\mails"
Set ns = GetNamespace("MAPI")
Set olFolder_Inbox = ns.GetDefaultFolder(olFolderInbox)
Set fso = CreateObject("Scripting.FileSystemObject")
For Each olMail In olFolder_Inbox.Items
If TypeName(olMail) = "MailItem" And olMail.Attachments.Count > 0 Then
fso.CreateFolder (fso.BuildPath(File_Saved_Folder_Path, Trim(olMail.Subject)))
For Each olAttachment In olMail.Attachments
olAttachment.SaveAsFile fso.BuildPath(File_Saved_Folder_Path, Trim(olMail.Subject)) & "\" & olAttachment.FileName
Next olAttachment
End If
Next olMail
Set olFolder_Inbox = Nothing
Set ns = Nothing
Set fso = Nothing
End Sub
但是當我執行宏時,我得到粗略的(從瑞典語翻譯):
錯誤 76,找不到路徑
我的錯誤是什么?
MailItem
class 的Subject
屬性和Attachment
class 的FileName
屬性可能包含不能用於文件名的禁止符號。 所以。 在調用Attachment
class 的SaveAsFile
方法之前,您需要檢查文件路徑是否存在此類文件夾並且路徑不包含禁止符號。 請參閱Windows 和 Linux 目錄名稱中禁止使用哪些字符? 了解更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.