none
How can I redraw/refresh the to-do bar in Outlook 2013 with VBA (and RDO if needed)? RRS feed

  • Question

  • I am using Outlook 2013. I have the To-Do Bar open on the right. I would like to make it so the flagged items it shows are only for the currently selected folder.

    I am using Explorer_BeforeFolderSwitch to trigger every time I change folders. Then I use RDO to modify the "To Do Search" hidden search folder SQL to filter for only items in that folder (by the new folder's Entry ID).

    Everything works except the To-Do Bar does not automatically refresh. I have to change into something else like the Calendar and then switch back to the Inbox for the To-Do Bar to refresh.

    ' the current explorer object
    Private WithEvents nOutlookExplorer As Explorer
    
    ' set the explorer object
    Private Sub Application_MAPILogonComplete()
        Set nOutlookExplorer = Application.ActiveExplorer
    End Sub
    
    ' triggered every time i change folders
    Private Sub nOutlookExplorer_BeforeFolderSwitch(ByVal NewFolder As Object, Cancel As Boolean)
    	Dim nSession As Object
    	Dim nToDoSearchFolder As Object
    	
    	' get an RDO session
    	Set nSession = CreateObject("Redemption.RDOSession")
    	nSession.Logon
    	
    	' find the to do folder, get its EntryID then get the folder
    	Set nToDoSearchFolder = nSession.GetFolderFromID(nSession.GetDefaultFolder(olFolderToDo).EntryID)
    	
    	' set the filter to flagged items whose parent folder matches this folder
    	nToDoSearchFolder.SearchCriteria.AsSQL = Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x10900003" & Chr(34) & " <> 1 AND " & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x10900003" & Chr(34) & " <> 0 AND " & Chr(34) & "urn:schemas:httpmail:messageflag" & Chr(34) & " IS NOT NULL AND " & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x0E090102" & Chr(34) & " = '" & NewFolder.EntryID & "'"
    	nToDoSearchFolder.Start
    	
    	Set nToDoSearchFolder = Nothing
        Set nSession = Nothing
    End Sub

    Thursday, April 21, 2016 8:02 PM

Answers

  • I go this to work. WOOT!

    Set nSession = CreateObject("Redemption.RDOSession")
    nSession.MAPIOBJECT = Application.session.MAPIOBJECT
    
    Set nStores = nSession.Stores
    Set nDefaultStore = nStores.defaultstore
    Set nSearchRootFolder = nDefaultStore.SearchRootFolder
    Set nFolders = nSearchRootFolder.Folders
    Set nToDoSearchFolder = nFolders.Item("To-Do Search")
    
    nToDoSearchFolder.SearchCriteria.AsSQL = Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x10900003" & Chr(34) & " <> 1 AND " & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x10900003" & Chr(34) & " <> 0 AND " & Chr(34) & "urn:schemas:httpmail:messageflag" & Chr(34) & " IS NOT NULL AND " & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x0E090102" & Chr(34) & " = '" & GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).EntryID & "'"
    nToDoSearchFolder.Start
    
    • Marked as answer by IMTheNachoMan Friday, April 22, 2016 8:00 PM
    Friday, April 22, 2016 8:00 PM

All replies

  • Will it work if you reset the Applicationb.ActiveExplorer.CurrentFolder property?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, April 21, 2016 8:05 PM
  • What do you mean by reset it? How would I do that?
    Thursday, April 21, 2016 8:28 PM
  • currentfolder = Application.ActiveExplorer.CurrentFolder ;
    Application.ActiveExplorer.CurrentFolder = Application.Session.GetDefautlFolder(olFolderInbox);
    Application.ActiveExplorer.CurrentFolder = currentfolder;


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Thursday, April 21, 2016 8:31 PM
  • Error on the 2nd line:

    Application.ActiveExplorer.CurrentFolder = Application.session.GetDefaultFolder(olFolderInbox)

    Run-time error '-2147024891 (80070005)
    
    You don't have appropriate permission to perform this operation.


    Thursday, April 21, 2016 8:50 PM
  • Try to use "set":

    set Application.ActiveExplorer.CurrentFolder = Application.session.GetDefaultFolder(olFolderInbox)

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, April 21, 2016 9:15 PM
  • Same error... :(
    Thursday, April 21, 2016 9:37 PM
  • Wait a sec, are you doing this in the BeforeFolderSwitch event handler?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, April 21, 2016 9:42 PM
  • Yes. Why, should I not be? I need to do it every time the user changes to a different folder.
    Thursday, April 21, 2016 11:10 PM
  • Setting Explorer.CurrentFolder will fire the BeforeFolderSwitch  event, so Outlook prevents you from this recursion.

    If this were not VBA, you could use a timer and execute the code after you are out of the event handler.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, April 21, 2016 11:17 PM
  • I just tried it outside of BeforeFolderSwitch and it still did not work.

    I am wondering if there is anyway to refresh the view for the To Do Bar?

    At first it uses the search folder as the "To Do Search" one but I've realized through the UI I can change the filters for both the "To Do" view and the "To Do Bar" independently.

    It's also not possible to remove SearchContainers for this SearchFolder using RDO but I'm going to post that to the Yahoo group.

    Friday, April 22, 2016 11:40 AM
  • What did not work? I had no problem running the script below from either OutlookSpy (click Script button) or VBA editor:

    set f = Application.Session.GetDefaultFolder(olFolderInbox)
    set Application.ActiveExplorer.CurrentFolder = f

    What is the problem removing search containers using RDO?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, April 22, 2016 2:00 PM
  • I am getting an error in trying to remove a container from a search folder. I was going to post to the Yahoo group or should I create a new thread in this forum?

    (By the way, love what you've done with RDO. It is a huge life savor.)

    Friday, April 22, 2016 3:37 PM
  • Either way should be fine...

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, April 22, 2016 3:57 PM
  • I go this to work. WOOT!

    Set nSession = CreateObject("Redemption.RDOSession")
    nSession.MAPIOBJECT = Application.session.MAPIOBJECT
    
    Set nStores = nSession.Stores
    Set nDefaultStore = nStores.defaultstore
    Set nSearchRootFolder = nDefaultStore.SearchRootFolder
    Set nFolders = nSearchRootFolder.Folders
    Set nToDoSearchFolder = nFolders.Item("To-Do Search")
    
    nToDoSearchFolder.SearchCriteria.AsSQL = Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x10900003" & Chr(34) & " <> 1 AND " & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x10900003" & Chr(34) & " <> 0 AND " & Chr(34) & "urn:schemas:httpmail:messageflag" & Chr(34) & " IS NOT NULL AND " & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x0E090102" & Chr(34) & " = '" & GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).EntryID & "'"
    nToDoSearchFolder.Start
    
    • Marked as answer by IMTheNachoMan Friday, April 22, 2016 8:00 PM
    Friday, April 22, 2016 8:00 PM