Save attachments when received. "runtime error:13 Type mismatch"
Save attachments when received. "runtime error:13 Type mismatch"
我的电子邮件中有几个看不见的电子邮件附件。当我从特定发件人那里收到它时,我想自动下载它。我正在使用 Outlook 2013。
我得到:
runtime error:13 Type mismatch
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
您可以创建一个 macro rules,当您收到来自特定发件人的电子邮件时 运行 一个脚本。
关于自动保存附件,可以参考这个link:
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 = "someone@example.com" 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
我的电子邮件中有几个看不见的电子邮件附件。当我从特定发件人那里收到它时,我想自动下载它。我正在使用 Outlook 2013。
我得到:
runtime error:13 Type mismatch
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
您可以创建一个 macro rules,当您收到来自特定发件人的电子邮件时 运行 一个脚本。
关于自动保存附件,可以参考这个link:
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 = "someone@example.com" 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