我正在使用BlueDevilFan VBA脚本向我展示Outlook 2013中的电子邮件的互联网标题。我一直在尝试修改VBA,以便它只输出'to'或'for'地址并丢弃所有其他文本,
以下是VBA脚本:
Sub ViewInternetHeader()
Dim olItem As Outlook.MailItem, olMsg As Outlook.MailItem
Dim strheader As String
For Each olItem In Application.ActiveExplorer.Selection
strheader = GetInetHeaders(olItem)
Set olMsg = Application.CreateItem(olMailItem)
With olMsg
.BodyFormat = olFormatPlain
.Body = strheader
.Display
End With
Next
Set olMsg = Nothing
End Sub
Function GetInetHeaders(olkMsg As Outlook.MailItem) As String
' Purpose: Returns the internet headers of a message.'
' Written: 4/28/2009'
' Author: BlueDevilFan'
' http://techniclee.wordpress.com/
' Outlook: 2007'
Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
Dim olkPA As Outlook.PropertyAccessor
Set olkPA = olkMsg.PropertyAccessor
GetInetHeaders = olkPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)
Set olkPA = Nothing
End Function
我尝试了类似于我会在单词中查找和删除某些内容的内容,但无法在Outlook中使用它!
Sub CleanUp()
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(\To: """)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
.Text = "(\To: """)"
.Execute Replace:=wdReplaceAll
End With
End With
End Sub
答案 0 :(得分:0)
你可以清除身体的文本,然后添加来自发件人
x
答案 1 :(得分:0)
为什么需要从标题中提取地址?只需遍历MailItem.Recipients
集合中的所有收件人,如果Recipient.Type = olTo
,请阅读Recipient.Address
属性/