【发布时间】:2018-08-31 01:04:17
【问题描述】:
我有这段代码,它可以将附件从 Outlook 中取出并放入本地文件夹。从那以后,我尝试对其进行修改以重命名文件并从 Outlook 中删除电子邮件,这就是它停止工作的地方。
该规则在电子邮件进入新文件夹时将其移动,然后将附件保存到我 C 盘上的文件夹中。每天只有 1 封电子邮件和 1 个附件。
我想将附件保存到文件夹,重命名附件(覆盖现有文件),然后从 Outlook 中删除电子邮件。
这是我目前的代码。
任何帮助将不胜感激
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 = "C:\Automation\CBM\"
'strfolderpath = strfolderpath & "\Attachments\"
' Combine with the path to the folder.
strFile = strfolderpath & strFile
' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile FilePath & "Daily_Activity_Report" &
".xlsx"
' Delete the attachment.
objAttachments.Item(i).Delete
Next i
End If
End Sub
【问题讨论】:
-
什么是
FilePath? -
标题“重命名和删除附件”与正文“重命名文件并删除电子邮件”不匹配。哪个是正确的?