vba - 从 Outlook 中的特定文件夹下载附件

标签 vba outlook outlook-2010

我对 vba 不太熟悉,无法根据我的需要修改它。

我需要从特定文件夹下载附件。

我找到了这个example ,但我不确定如何获取这些电子邮件发送到的文件夹。

我有一个规则,当这些电子邮件进来时,它会将它们放入不同的文件夹中。

这是我想要运行宏的地方,因此它只从这些电子邮件中删除附件并将它们放在本地计算机文件夹中。

我需要更改哪些部分才能使其满足我的需求?

Public Sub SaveAttachments(Item As Outlook.MailItem)

If Item.Attachments.Count > 0 Then

Dim objAttachments As Outlook.Attachments
Dim lngCount As Long
Dim strFile As String
Dim sFileType As String
Dim i As Long

Set objAttachments = Item.Attachments
    lngCount = objAttachments.Count
 For i = lngCount To 1 Step -1

' Get the file name.
 strFile = objAttachments.Item(i).FileName

 ' Get the path to your My Documents folder
    strfolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    strfolderpath = strfolderpath & "\Attachments\"

' Combine with the path to the folder.
 strFile = strfolderpath & strFile

' Save the attachment as a file.
 objAttachments.Item(i).SaveAsFile strFile

 Next i
End If

End Sub

最佳答案

要打开与收件箱同一级别的文件夹,请打开收件箱,然后转到其父级,然后按名称检索文件夹:

set MyFolder = Application.Session.GetDefaultFolder(olFolderInbox).Parent.Folders.Item("My Folder Name")

关于vba - 从 Outlook 中的特定文件夹下载附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35994435/

相关文章:

excel - 如何根据excel中的另一个单元格值限制单元格中的值输入/输入?

Excel:使用 VBA 在一行中查找最右边(最后一次)出现的值

excel - 如何使用 Excel 中存储的地址向多个收件人发送电子邮件?

c# - 如何捕获电子邮件

c# - 为什么 outlook 嗅探器不处理我的日历邀请?

c# - 根据发件人地址中的单词指定 Outlook 规则条件

.net - 为什么 VBA 的 VarType 函数说这个 COM 对象是一个字符串? (Object 是 .NET 的 System.Object 类的 COM 版本的实例。)这是一个错误吗?

excel - 如果列中的字符串左对齐,如何获取信息以及如何在另一个工作表中使用此信息创建新单元格?

javascript - 文本到 Outlook 正文

Outlook 表格宽度问题中的 HTML 电子邮件 - 内容比指定的表格宽度宽