我是宏的新手。我在Windows 10上为Outlook 2016编写了一个宏,该宏将多封电子邮件保存到我的Excel文件夹(即E:\SUMMARYS
)中,并带有.msg扩展名,但是我需要保存文件名而不是“日期和时间”它是在每封电子邮件的正文中找到的发票参考号(即参考号:700PG243)。
我每天都会收到许多带有不同发票参考号的发票电子邮件,它们仅在电子邮件正文中找到。保存后,需要将电子邮件自动标记为已读,然后将其移动到我的Outlook的子文件夹中,名为 Invoices 2019 。
Sub SaveSelectedMessages()
Dim olItem As Outlook.MailItem
Dim fName As String
Dim fPath As String
fPath = "E:\SUMMARYS\"
For Each olItem In ActiveExplorer.Selection
fName = Format(olItem.ReceivedTime, "yyyymmdd") & Chr(32) & _
Format(olItem.ReceivedTime, "HH.MM") & Chr(32) & _
olItem.SenderName & " - " & olItem.Subject & ".msg"
fName = Replace(fName, Chr(58) & Chr(41), "")
fName = Replace(fName, Chr(58) & Chr(40), "")
fName = Replace(fName, Chr(34), "-")
fName = Replace(fName, Chr(42), "-")
fName = Replace(fName, Chr(47), "-")
fName = Replace(fName, Chr(58), "-")
fName = Replace(fName, Chr(60), "-")
fName = Replace(fName, Chr(62), "-")
fName = Replace(fName, Chr(63), "-")
fName = Replace(fName, Chr(124), "-")
olItem.SaveAs fPath & fName
Next olItem
Set olItem = Nothing
End Sub