自动从Outlook 2013下载/保存附件到某个文件夹。以下编写的脚本说“运行时错误:13类型不匹配”

问题描述 投票:2回答:1

我在办公室电子邮件中有几个看不见的电子邮件附件。每当我从特定发件人收到它时,我想自动下载它。我正在使用outlook 2013。

Private Sub Application_NewMail()

Dim onamespace As Outlook.NameSpace
Set onamespace = Outlook.GetNamespace("MAPI")

Dim myfol As Outlook.Folder
Set myfol = onamespace.GetDefaultFolder(olFolderInbox)

Dim omail As Outlook.MailItem
Set omail = Outlook.CreateItem(olMailItem)
Dim atmt As Outlook.attachment

For Each omail In myfol.Items

    If omail.SenderEmailAddress = "@gmail.com" Then

        For Each atmt In omail.Attachments

            atmt.SaveAsFile "C:\Users\raj\Downloads\" & atmt.fileName

        Next

    Else
    End If

Next

End Sub

提前致谢!拉吉

vba download outlook attachment
1个回答
1
投票

当您收到来自特定发件人运行脚本的电子邮件时,您可以创建macro rules

关于自动保存附件,您可以参考以下链接:

Public Sub Save_Attachment(olItem As Outlook.MailItem)
    Dim olAttch As Outlook.Attachment
    Dim sPath As String

    'sPath = Environ("USERPROFILE") & "\Documents\"
    sPath = "C:\Temp\"

For Each olAttch In olItem.Attachments
       If olAttch.UnRead = True Then
           If olAttch.SenderEmailAddress = "[email protected]" Then
               olAttch.SaveAsFile sPath & "\" & olAttch.DisplayName
               olAttch.UnRead = false
           End If
       End If
    Next

    Set olAttch = Nothing
End Sub

参考来自:

Save attachment with incoming email sender's name or email address

© www.soinside.com 2019 - 2024. All rights reserved.