您好我有一个VB脚本,但我目前无法测试它。有没有人知道VB脚本是否在.msg文件中自动显示消息正文而不在脚本中定义它?
这是我的代码:
Option Explicit
Public Enum olSaveAsTypeEnum olSaveAsTxt = 0 olSaveAsRTF = 1
olSaveAsMsg = 3 End Enum
Private WithEvents Items As Outlook.Items
Private Const MAIL_PATH As String = "d:\mails\"
Private Sub Application_Startup() Dim Ns As Outlook.NameSpace
Set Ns = Application.GetNamespace("MAPI") Set Items =
Ns.GetDefaultFolder(olFolderInbox).Items End Sub
Private Sub Items_ItemAdd(ByVal Item As Object) If TypeOf Item Is
Outlook.MailItem Then
SaveMailAsFile Item, olSaveAsMsg, MAIL_PATH End If End Sub
Private Sub SaveMailAsFile(oMail As Outlook.MailItem, _ eType As
olSaveAsTypeEnum, _ sPath As String _ ) Dim dtDate As Date Dim
sName As String Dim sFile As String Dim sExt As String
Select Case eType
Case olSaveAsTxt: sExt = ".txt"
Case olSaveAsMsg: sExt = ".msg"
Case olSaveAsRTF: sExt = ".rtf"
Case Else: Exit Sub End Select
sName = oMail.Subject ReplaceCharsForFileName sName, "_"
dtDate = oMail.ReceivedTime sName = Format(dtDate, "yyyymmdd",
vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, "-hhnnss", _
vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & sExt
oMail.SaveAs sPath & sName, eType 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 = Replce(sName, "<", sChr) sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr) End Sub
答案 0 :(得分:0)
是的,以MSG格式保存可以在MSG文件中保存纯文本,HTML和RTF正文风格。