【发布时间】:2020-06-23 15:42:38
【问题描述】:
以下代码从存储在一个文件夹中的 *.msg 文件中提取附件。
我正在寻求从存储在文件夹内许多子文件夹中的 *.msg 文件中提取附件。
主文件夹的路径是:
U:\XXXXX\XXXXX\主文件夹
子文件夹的路径是:
U:\XXXXX\XXXXX\主文件夹\Folder1
U:\XXXXX\XXXXX\主文件夹\Folder2
U:\XXXXX\XXXXX\主文件夹\Folder3
等等
Sub SaveOlAttachments()
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String
'path for msgs
strFilePath = "U:\XXXXX\XXXXX\Main Folder\"
'path for saving attachments
strAttPath = "D\Attachments\"
strFile = Dir(strFilePath & "*.msg")
Do While Len(strFile) > 0
Set msg = Application.CreateItemFromTemplate(strFilePath & strFile)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.FileName
Next
End If
strFile = Dir
Loop
End Sub
【问题讨论】:
-
非常感谢蒂姆您的及时回复。非常感激。由于我的 VBA 知识有限,您能帮我一个忙并将这两个代码组合在一起。再次感谢蒂姆 :)
-
谢谢 FoxCy。如果可以将代码组合在一起以从生成的 *.msg 文件中提取所有附件,我将不胜感激。赞赏。
标签: vba outlook subdirectory email-attachments msg