从Outlook中的特定文件夹下载附件 [英] Download attachments from specific folder in Outlook
问题描述
我对vba不够熟悉,无法根据需要对其进行修改.
I am not familiar with vba enough to modify this for my needs.
我需要从特定文件夹下载附件.
I need to download the attachments from a specific folder.
我找到了这个示例,但是我我不确定如何获取将这些电子邮件发送到的文件夹.
I found this example, but I am not sure how to get the folder where these emails are sent to.
我有一条规则,当这些电子邮件进入时,会将它们放置在另一个文件夹中.
I have a rule that when these emails come in, it places them into a different folder.
我要在其中运行宏的位置,以便仅从这些电子邮件中剥离附件并将它们放置在本地计算机文件夹中.
This where I want to run the macro so it only strips the attachments from these emails and places them on the local computer folder.
我需要更改哪些部分才能使其满足我的需要?
What parts do I need to change to get this to work for my needs?
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
推荐答案
要打开与收件箱"相同级别的文件夹,请打开收件箱",然后再向上一级转到其父文件夹,然后按名称检索文件夹:>
To open a folder on the same level as your Inbox, open Inbox, then go one level up to its parent, then retrieve your folder by name:
set MyFolder = Application.Session.GetDefaultFolder(olFolderInbox).Parent.Folders.Item("My Folder Name")
这篇关于从Outlook中的特定文件夹下载附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!