使用Outlook VBA将选定的电子邮件保存为文本文件 [英] Using Outlook VBA to save selected email(s) as a text file
本文介绍了使用Outlook VBA将选定的电子邮件保存为文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将Outlook中所选的电子邮件保存为文本文件。
I am trying to save selected emails in Outlook as Text files.
我希望这样工作:
-
保存一个电子邮件一次,但保存所有选定的电子邮件,而不是一个电子邮件。
Saves one email at a time but saves all selected emails instead of just a single email.
他们需要将它们保存为新文件。我知道导出功能将它们全部保存为一个大文本文件,但需要它们各自拥有。
They need to each be saved as a new file. I know that the export feature saves them all as one large text file, but need them to each have their own.
以下是我到目前为止:
Sub SaveEmail()
Dim Msg As Outlook.MailItem
' assume an email is selected
Set Msg = ActiveExplorer.Selection.item(2)
' save as text
Msg.SaveAs "C:\My Location", OLTXT
End Sub
推荐答案
感谢大家的帮助。我能找到答案。以下是对我有用的。
Thank you everybody for your help. I was able to find the answer. Below is what worked for me.
Sub SaveSelectedMailAsTxtFile()
Const OLTXT = 0
Dim currentExplorer As Explorer
Dim Selection As Selection
Dim oMail As Outlook.MailItem
Dim obj As Object
Dim sPath As String
Dim dtDate As Date
Dim sName As String
Set currentExplorer = Application.ActiveExplorer
Set Selection = currentExplorer.Selection
For Each obj In Selection
Set oMail = obj
sName = oMail.Subject
ReplaceCharsForFileName sName, "_"
dtDate = oMail.ReceivedTime
sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, "-hhnnss", _
vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".txt"
oMail.SaveAs "C:\my\path\" & sName, OLTXT
Next
End Sub
Private Sub ReplaceCharsForFileName(sName As String, _
sChr As String _
)
sName = Replace(sName, "/", sChr)
sName = Replace(sName, "\", sChr)
sName = Replace(sName, ":", sChr)
sName = Replace(sName, "?", sChr)
sName = Replace(sName, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
End Sub
这篇关于使用Outlook VBA将选定的电子邮件保存为文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文