乍一看Luke123的“附加标签到Outlook”请求的要求非常相似。 在这里,我需要将自动编号任务ID(仅特定于此要求)附加到Outlook Exchange(共享)邮箱的主题行中。
因此,这需要a)自动编号和b)在电子邮件登陆时自动运行。
共享邮箱的相当规则在服务器端运行,并被业务锁定。
感谢所有的想法/帮助。
答案 0 :(得分:0)
这段代码很可能需要调整,但应该做你想要的。您可能需要获取现有的收件箱项目并为其提供任务ID,以便让球滚动。有关代码的说明以及您需要编辑的地方,请参阅我的评论。
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Set olApp = Outlook.Application
' edit this line to reflect the actual mailbox name as displayed in Outlook
Set Items = Session.Folders("Mailbox - My Shared Mailbox").Folders("Inbox")
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
Dim msg As Outlook.mailItem
Dim firstObj As Object
Dim i As Long
Dim firstMsg As Outlook.mailItem
Dim currentTaskID As String
Dim nextTaskID As Long
If TypeName(item) = "MailItem" Then ' it's an email
Set msg = item
' get first email from Inbox to determine next task ID
Do Until TypeName(firstObj) = "MailItem" Or i = Session.Folders("Mailbox - My Shared Mailbox").Folders("Inbox").Items.Count
i = i + 1
' might have to start at item #2?
Set firstObj = Session.GetDefaultFolder(olFolderInbox).Items(i)
Loop
' typecast the object to mailitem for Intellisense
If TypeName(firstObj) = "MailItem" Then
Set firstMsg = firstObj
Else
' display messagebox?
Goto ProgramExit
End If
' get task id and calculate next value, let's assume it's the last three chars of subject
' Ex: Subject: Incoming Email - TaskId: 001
currentTaskID = Right$(firstMsg.Subject, 3)
nextTaskID = CLng(currentTaskID) + 1
' put next task ID number into new email's subject
With msg
.Subject = msg.Subject & " - TaskId: " & nextTaskID
.Save
End With
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub