{"id":7993,"date":"2018-03-16T16:42:46","date_gmt":"2018-03-16T20:42:46","guid":{"rendered":"http:\/\/nycphantom.com\/journal\/?p=7993"},"modified":"2018-03-16T16:46:10","modified_gmt":"2018-03-16T20:46:10","slug":"outlook-macro-dealing-with-new-mail-and-reminders","status":"publish","type":"post","link":"https:\/\/nycphantom.com\/journal\/?p=7993","title":{"rendered":"Outlook Macro - Dealing with New Mail and Reminders"},"content":{"rendered":"<p>Just for the record, in Outlook VBA &gt; ThisOutlookSession:<\/p>\n<pre id=\"codeblock_Outlook-ThisOutlookSession\" class=\"codeblock codeblock_none\"><code>&#039;&#039; Move Outlook to top when new mail arrives\r\n&#039;Private Sub Application_NewMail()\r\n&#039;    Outlook.Application.ActiveWindow.Activate\r\n&#039;End Sub\r\n\r\n\r\n\r\n&#039;https:\/\/www.tachytelic.net\/2017\/10\/how-to-run-a-vba-macro-when-new-mail-is-received-in-outlook\/\r\nOption Explicit\r\nPrivate WithEvents inboxItems As Outlook.Items\r\n\r\n&#039; declare this object withEvents displaying all the events\r\nPrivate WithEvents olRemind As Outlook.Reminders\r\nDim ReminderAccount As String\r\n\r\n\r\nPrivate Sub Application_Startup()\r\n  Dim outlookApp As Outlook.Application\r\n  Dim objectNS As Outlook.NameSpace\r\n  \r\n  Set outlookApp = Outlook.Application\r\n  Set objectNS = outlookApp.GetNamespace(&quot;MAPI&quot;)\r\n  Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items\r\nEnd Sub\r\n\r\n\r\nPrivate Sub inboxItems_ItemAdd(ByVal Item As Object)\r\nOn Error GoTo ErrorHandler\r\nDim Msg As Outlook.MailItem\r\nDim MessageInfo\r\nDim Result\r\nIf TypeName(Item) = &quot;MailItem&quot; Then\r\n&#039;    MessageInfo = &quot;&quot; &amp; _\r\n&#039;        &quot;Sender : &quot; &amp; Item.SenderEmailAddress &amp; vbCrLf &amp; _\r\n&#039;        &quot;Sent : &quot; &amp; Item.SentOn &amp; vbCrLf &amp; _\r\n&#039;        &quot;Received : &quot; &amp; Item.ReceivedTime &amp; vbCrLf &amp; _\r\n&#039;        &quot;Subject : &quot; &amp; Item.Subject &amp; vbCrLf &amp; _\r\n&#039;        &quot;Size : &quot; &amp; Item.Size &amp; vbCrLf &amp; _\r\n&#039;        &quot;Message Body : &quot; &amp; vbCrLf &amp; Item.Body\r\n&#039;    Result = MsgBox(MessageInfo, vbOKOnly, &quot;New Message Received&quot;)\r\n\r\n    Outlook.Application.ActiveWindow.Activate\r\n\r\nEnd If\r\nExitNewItem:\r\n    Exit Sub\r\nErrorHandler:\r\n    MsgBox Err.Number &amp; &quot; - &quot; &amp; Err.Description\r\n    Resume ExitNewItem\r\nEnd Sub\r\n\r\n\r\n\r\n&#039; Dismisses Reminders based on Accounts, before they appear. This works together with Private WithEvents olRemind from top of the code.\r\nPrivate Sub Application_Reminder(ByVal Item As Object)\r\n    Set olRemind = Outlook.Reminders\r\n    ReminderAccount = Item.Parent.Parent\r\nEnd Sub\r\n\r\nPrivate Sub olRemind_BeforeReminderShow(Cancel As Boolean)\r\n    Dim objRem As Reminder\r\n    For Each objRem In olRemind\r\n                If objRem.IsVisible And ReminderAccount = &quot;TLaw@solomonpage.com&quot; Then\r\n                    MsgBox ReminderAccount\r\n                    objRem.Dismiss  &#039; dismisses reminder\r\n                    Cancel = True   &#039; takes out the reminder window\r\n                End If\r\n                Exit For\r\n        Next objRem\r\n\r\nEnd Sub\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just for the record, in Outlook VBA &gt; ThisOutlookSession:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-7993","post","type-post","status-publish","format-standard","hentry","category-technical"],"_links":{"self":[{"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/7993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7993"}],"version-history":[{"count":3,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/7993\/revisions"}],"predecessor-version":[{"id":7996,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/7993\/revisions\/7996"}],"wp:attachment":[{"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}