我从SharePoint网站收到警报,并从SharePoint警报电子邮件正文中提取“请求者电子邮件”和“提交者电子邮件”。这些电子邮件成为转发SharePoint警报的电子邮件的TO:和CC :.
我可以让宏工作在它自己的工作,但不能“自动”在Outlook中收回电子邮件。
我发布了宏,但它不适用于最近收到的或新的警报电子邮件。转发电子邮件是通过以前收到的(和已读取的)电子邮件生成的,并继续从之前的同一封电子邮件生成转发电子邮件。
我认为NewMailEx会解决宏在最近的rec(或新电子邮件)上没有触发的问题,但事实并非如此。
这是我粘贴到ThisOutlookSession
的代码Option Explicit
Private objNS As Outlook.NameSpace
Private WithEvents objNewMailItems As Outlook.Items
Private Sub Application_Startup()
Dim objMyInbox As Outlook.MAPIFolder
Set objNS = Application.GetNamespace("MAPI")
Set objMyInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objNewMailItems = objMyInbox.Items
Set objMyInbox = Nothing
End Sub
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Call OnetimeFwdSelToAddr
End Sub
OnetimeFwdSelToAddr就在这里(我没有包含解析函数parsetextlinepair ......那部分似乎工作正常)
Sub OnetimeFwdSelToAddr()
Dim objOL As Outlook.Application
Dim objItem As Object
Dim objFwd As Outlook.mailitem
Dim strAddr As String
Dim strAddr2 As String
On Error Resume Next
Set objOL = Application
Set objItem = objOL.ActiveExplorer.Selection(1)
If Not objItem Is Nothing Then
strAddr = ParseTextLinePair(objItem.Body, "Requestor Email:")
strAddr2 = ParseTextLinePair(objItem.Body, "Submitter Email:")
If strAddr <> "" Then
Set objFwd = objItem.Forward
With objFwd
.HTMLBody = "edited out my email text here" & vbCr & .HTMLBody
.SentOnBehalfOfName = "othermail@asdf.com"
End With
objFwd.To = strAddr
objFwd.CC = strAddr2
objFwd.Display
Else
MsgBox "Could not extract address from message."
End If
End If
Set objOL = Nothing
Set objItem = Nothing
Set objFwd = Nothing
End Sub
答案 0 :(得分:0)
这描述了如何使用NewMailEx http://msdn.microsoft.com/fr-fr/library/office/ff863686(v=office.15).aspx
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim varEntryIDs
Dim objItem
Dim i As Integer
varEntryIDs = Split(EntryIDCollection, ",")
For i = 0 To UBound(varEntryIDs)
Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))
Debug.Print "NewMailEx " & objItem.Subject
Next
End Sub
您可以将objItem作为参数而不是Set objItem = objOL.ActiveExplorer.Selection(1)
传递