Community Pick: Many members of our community have endorsed this article.
Editor's Choice: This article has been selected by our editors as an exceptional contribution.

Add-On for Reducing EE Email Clutter using Outlook

Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Published:
Updated:

This is an Add-On procedure to be used in conjunction with the code provided in Reducing EE Email Clutter using Outlook, because it uses the "tagging system" of that article.


Purpose

Imagine the following situation: You have read the prior article, and implemented the code provided, and your EE Email is organized in a better way now.  Maybe you even used conditional colouring to emphasize specific topics.
But you have still 500 notification mails for the last 4 days in your inbox informing you about new questions you have set a filter for, or neglected questions of areas you are a Designated Expert in.  You pick one or another of those questions, maybe posted the prior day already, to provide suggestions.  You go into the questions, and find them answered and closed already.

Well, that can't happen anymore, if you apply this code on all or some of your questions! It will go thru the (EE assigned) inbox completely (if nothing is selected), or only thru the selected posts, and look whether the question is already closed or deleted. If so, it is removed from the inbox, and you can be sure about each remaining question being worth to have a look into it.

For Page Editors: The code also checks for deleted articles, and removes the notif then. It is more difficult to extend to check for the other states, like Editor or Author Review, or (Re-)Published, since that is not reflected in the printer-friendly version.


Inside the code

Since it isn't much of code, I'll provide it "inline" here. But before you can use it, you need to put
 
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliSeconds As Long)

Open in new window

at the very beginning of the VBA Module you add the code to (before any procedure or function declaration).
In addition you need to add a reference to IE. While in the VBA Editor, choose Extras » References, search for "Microsoft Internet Controls" and tick it. That allows us to use Early Binding of Internet Explorer, that is we can directly access its properties. For a property description, see MSDN.

 
Sub CheckForClosed()
                      Static Web As InternetExplorer
                      Dim pos0, pos1 As Integer
                      Dim str, c As String
                      Dim Sel
                      Dim ml As MailItem
                      Dim q#, del#, sol#
                      Dim isArticle As Boolean
                       
                        If Web Is Nothing Or TypeName(Web) <> "IWebBrowser2" Then Set Web = CreateObject("InternetExplorer.Application")
                        ' Web.Visible = True
                          
                        Set Sel = myOlEEItems
                        If Outlook.ActiveExplorer.Selection.Count > 0 Then
                          If TypeName(Outlook.ActiveExplorer.Selection.item(1)) = "MailItem" Then
                            Set Sel = Outlook.ActiveExplorer.Selection
                          End If
                        End If
                        
                        For Each ml In Sel
                          str = ""
                          On Error Resume Next
                          str = ml.UserProperties("Reference")
                          q# = q# + 1
                          On Error GoTo 0
                          If str <> "" Then
                            isArticle = (Left(str, 1) = "A")
                            If isArticle Then
                              str = "http://e-e.com/viewArticlePrinterFriendly.jsp?articleID=" & Mid$(str, 3)
                            Else
                              str = "http://e-e.com/viewQuestionPrinterFriendly.jsp?qid=" & Mid$(str, 3)
                            End If
                            Web.Navigate (str)
                            While Web.ReadyState <> READYSTATE_COMPLETE: Sleep 10: Wend
                            str = LCase(Left$(Web.Document.Body.InnerHtml, 2000))
                            If isArticle Then
                              str = Mid$(str, InStr(str, "<div class=""postabletype"">") + Len("<div class=""postabletype"">"))
                            Else
                              str = Mid$(str, InStr(str, "<div class=""questiontype"">") + Len("<div class=""questiontype"">"))
                            End If
                            str = Left$(str, InStr(str, "</div>") - 1)
                            str = Trim(Replace(str, Chr(10), ""))
                            c = "."
                            If str = "solution" Then ml.Delete: sol# = sol# + 1: c = "+"
                            If str = "<span style=""color: #ff0000"">deleted</span> question" Then ml.Delete: del# = del# + 1: c = "-"
                            If str = "<span style=""color: #ff0000"">deleted</span> article" Then ml.Delete: del# = del# + 1: c = "-"
                            Debug.Print c;
                          End If
                        Next
                        
                        Debug.Print Chr(13) & "Q: " & q# & "   Solved: " & sol# & "   Deleted: " & del#
                        
                        Web.Quit
                        Set Web = Nothing
                        
                      End Sub

Open in new window

To use the code, I recommend to create a toolbar button, and assign the macro call to it. I have created this one for Outlook 2003:
 My Button layoutThe macro uses the InternetExplorer control to request a "printer friendly" version of pages. This is faster and contains less "clutter" then the usual views, and eases the parsing of the received HTML code.
Each page then is parsed for the question (or article) header, which tells us if it is closed or deleted.

After all (selected) mails have been processed, the debugger output presents a summary of the amount of questions processed, and how many of them were solved or deleted. You will see that only in the Direct Window of the VBA Editor, which you can switch on by pressing Ctrl-G.


"Obvious" Improvements

This macro uses an synchronous approach, processing  only one question at any time. It could have been done asynchronous, by using more than one IE (or IE Tab), and corresponding Event handlers, processing a shared queue. The result could be a "multi-threaded" processing of more than one question in-parallel.
I have to admit I tried that, but it is too complex because of the limitations Outlook, VBA and the InternetExplorer Events impose. For example you can't get DocumentComplete Events for each tab if using a tabbed browser – only the first tab's events are catched. And changing that requires to use one browser per question, and one event handler per browser – which again requires you to have a static setup of those. Feasible, but cumbersome.

It would be great if you could limit the amount of data retrieved for displaying a page. As-is, the code has to retrieve the full printer-friendly rendered thread, just to read the top let's say 500 bytes.
1
6,369 Views
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT

Comments (1)

Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Author

Commented:
With EE v.10 this Add-On stopped working (as expected). Since I will (probably) have to switch to read XML streams instead of the printer-friendly page, getting it working again might last a while.

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.