简体   繁体   English

保存所有 outlook 附件

[英]Save all outlook attachments

I want to save all attachments from my Outlook 365 inbox.我想保存 Outlook 365 收件箱中的所有附件。

Copying this tutorial I wrote:复制本教程我写道:

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

But when I execute the macro I get roughly (translated from swedish):但是当我执行宏时,我得到粗略的(从瑞典语翻译):

Error 76, Cant find the path错误 76,找不到路径

What's my mistake?我的错误是什么?

Looks like it could be either a mistake in the path or a bunch of other stuff as quoted below from a blog post .看起来它可能是路径中的错误或下面从博客文章中引用的一堆其他东西。

Runtime Error 76 will typically show when your computer cannot read a file it requires, either because it's damaged, misplaced or not registered.运行时错误 76 通常会在您的计算机无法读取它需要的文件时显示,因为它已损坏、放错位置或未注册。

Did you try any of the fixes in available posts/guides?您是否尝试过可用帖子/指南中的任何修复? Maybe some will work or at least generate useful info, like the one from Microsoft if you haven't tried it yet!也许有些会起作用,或者至少会产生有用的信息,如果你还没有尝试过的话,比如来自Microsoft的信息!

The Subject property of the MailItem class and the FileName property of the Attachment class may contain forbidden symbols that can't be used for filenames. MailItem class 的Subject属性和Attachment class 的FileName属性可能包含不能用于文件名的禁止符号。 So.所以。 before calling the SaveAsFile method of the Attachment class you need to check the file path whether such folder exists and the path doesn't contain forbidden symbols.在调用Attachment class 的SaveAsFile方法之前,您需要检查文件路径是否存在此类文件夹并且路径不包含禁止符号。 See What characters are forbidden in Windows and Linux directory names?请参阅Windows 和 Linux 目录名称中禁止使用哪些字符? for more information.了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM