本文主要是介绍VBA发Out-of-office in outlook,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
单位的Jira 和Outlook联系的不够紧密,总之OOO的状态无法让那些Jira上发任务Ticket的人知道,这么着还是挺容易误事的。遂做了一个VBA 工具,小规模解决下这个问题。
另外,TrustCentre里面的Macro Setting要改一改,至少改到,所有的轰都prompted,或者就直接允许。这个会有一些宏病毒风险。
Private WithEvents Items As Outlook.Items'Create for Jira OutOfOffice Notice email in outlook
'Please review below comment lines and change the info according to you
'Alt+F11 switch to VB Editor, paste the code to "ThisOutlookSession"
'Go to Trust Center under Macro tab, Trust all Macro, or if it is signed, you can just trust VBA with Signature
'Restart outlookPrivate Sub Application_Startup()Dim olApp As Outlook.ApplicationDim objNS As Outlook.NameSpaceSet olApp = Outlook.ApplicationSet objNS = olApp.GetNamespace("MAPI")' default local InboxSet Items = objNS.GetDefaultFolder(olFolderInbox).Folders("Jira").Items 'Change to Jira Folder if you have any...
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)On Error GoTo ErrorHandlerDim oNS As Outlook.NameSpaceDim oStores As Outlook.StoresDim oStr As Outlook.StoreDim oPrp As Outlook.PropertyAccessorDim olReply As ObjectDim myName As StringmyName = "MSS" 'Change to your email display nameSet oNS = Outlook.GetNamespace("MAPI")Set oStores = oNS.StoresDim Msg As Outlook.MailItemFor Each oStr In oStoresIf oStr.ExchangeStoreType = olPrimaryExchangeMailbox ThenSet oPrp = oStr.PropertyAccessorIf (oPrp.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B") = True) Then 'Check OOO statusIf TypeName(item) = "MailItem" ThenSet Msg = itemIf InStr(Trim(Msg.Sender), myName) <= 0 And InStr(Trim(Msg.Sender), "(JIRA)") > 0 Then 'Only Jira sent mail would be replyFor k = Msg.Recipients.Count To 1 Step -1If Msg.Recipients.item(k) = myName Then 'In case you send it to yourselfSet olReply = Msg.ReplyAllolReply.Recipients.Remove (1)strNum = InStr(Trim(Msg.Sender), "(") - 1SenderName = Trim(Mid(Trim(Msg.Sender), 1, strNum))Set olRecip = olReply.Recipients.Add(Replace(SenderName, " ", ".") & "@wswswsws.com")olReply.HTMLBody = "Hello, Thank you." & vbCrLf & _"As I'm currently out of office please contact my manager for urgent JIRA tasks." & vbCrLf & olReply.HTMLBodyolReply.SendExit ForEnd IfNextEnd IfEnd IfEnd IfEnd IfNextProgramExit:Exit Sub
ErrorHandler:MsgBox Err.Number & " - " & Err.DescriptionResume ProgramExit
End Sub
这篇关于VBA发Out-of-office in outlook的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!