【发布时间】:2022-08-13 21:23:04
【问题描述】:
我想保存 Outlook 365 收件箱中的所有附件。
复制this tutorial 我写道:
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,找不到路径
-
我假设您在 fso.CreateFolder (fso.BuildPath(File_Saved_Folder_Path, Trim(olMail.Subject))) 行收到错误?如果是这样,请确保您的主题不包含special characters(因为文件不能包含它们)。还要限制你的主题以防万一,这样你就不会在命名时创建太大的路径
标签: vba outlook office365 filepath email-attachments