从Outlook保存电子邮件附件到文件

时间:2015-04-22 15:06:35

标签: vba email outlook outlook-vba

我正在尝试使用VBA下载特定outlook文件夹中的附件,保存在我的硬盘驱动器上的文件(使用该文件的名称),然后删除该电子邮件。

在以下代码行中,我收到一条错误消息,指出该路径不存在。我正在复制并粘贴路径,所以它应该是正确的。

atmt.SaveAsFile FileName

整个代码在

之下
Dim ns As Namespace
Dim inbox As MAPIFolder
Dim item As Object
Dim atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim SubFolder As MAPIFolder
Dim SubSubFolder As MAPIFolder
Dim VariableName As Name
Set ns = getnamespace("MAPI")
Set inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = inbox.Folders("Consulta Emails - Passivo
Set SubSubFolder = inbox.Folders("Consulta Emails - Lastro")

i = 0

If SubFolder.Items.Count = 0 Then
MsgBox "Ainda não recebeu as planilhas necessárias"
Exit Sub
Else: End If
If SubFolder.Items.Count > 0 Then
For Each item In SubFolder.Items
For Each atmt In item.attachments
    FileName = "\dsapc429pfs.pactual.net\homefolder02$\wellsty\Desktop\Arthur Projects\Controle de Lastros\March tests\Consulta Passivo - Email.xls" 'muda path; vai salvar com o mesmo nome'
    atmt.SaveAsFile FileName
i = i + 1
item.Delete 'apagar os emails depois de baixar os anexos'
Next atmt
Next item
End If

1 个答案:

答案 0 :(得分:0)

尝试指定任何本地位置。将附件保存到磁盘后,您可以将保存的文件移动到任何需要的位置。