簡體   English   中英

保存所有 outlook 附件

[英]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,找不到路徑

我的錯誤是什么?

看起來它可能是路徑中的錯誤或下面從博客文章中引用的一堆其他東西。

運行時錯誤 76 通常會在您的計算機無法讀取它需要的文件時顯示,因為它已損壞、放錯位置或未注冊。

您是否嘗試過可用帖子/指南中的任何修復? 也許有些會起作用,或者至少會產生有用的信息,如果你還沒有嘗試過的話,比如來自Microsoft的信息!

MailItem class 的Subject屬性和Attachment class 的FileName屬性可能包含不能用於文件名的禁止符號。 所以。 在調用Attachment class 的SaveAsFile方法之前,您需要檢查文件路徑是否存在此類文件夾並且路徑不包含禁止符號。 請參閱Windows 和 Linux 目錄名稱中禁止使用哪些字符? 了解更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM