Allow Outlook redraw with Add-in

  • Thread starter Thread starter Mark S.
  • Start date Start date
M

Mark S.

What is the preferred method to allow Outlook to refresh
the explorer windows. (for example when moving items
into folders, the unread count should be updated)

I am perform fairly lengthy operations at times in an add-
in and it looks as if Outlook is hung while the add-in is
working.
 
If you are using a tight loop that is preventing Outlook from updating
things (since all addin code runs in-process with Outlook), you can sprinkle
in DoEvents statements at various places, which might help.
 
Thanks. I did that as shown in the following code
snippet:

Private Sub SyncItems_SyncEnd()
Dim Item As Object
Dim theFolder as Folders

theFolder = _
Outlook.Session.GetDefaultFolder(olFolderInbox)

For Each Item In theFolder.Items
Select Case Item.Class
Case olMail
theItemProcess(Item)
' Move item out of the inbox
Item.Move theProcessedFolder
DoEvents
End Select
Next
End Sub

A new interesting problem has popped up.
Imagine there are 18 mail items in the inbox. When this
code runs only 9 (about one half) items are processed.
Then on the next sync_end() event, again only about half
are processed (5 in this case, 4 are left in Inbox).
Then on next sync_end() 2 are processed leaving 2 in
Inbox. And so on until eventually all are processed.

Could calling DoEvents affect theFolder.Items in the
For/Next loop? Remember the items are being moved to
another folder after processing. Very odd.
 
Never move or delete items that way. Always use a down counting loop so you
aren't messing with the count of items which serves as your loop counter.
That's with or without DoEvents. The symptoms are exactly what you describe

Instead use:

For i = maxNumber To 1 Step -1
 
That is exactly what I ended up doing. Actually, without
the doevents() in a tight loop I guess Outlook never got
a chance to update the collection... But I wouldn't want
to rely on that. Thanks for the help.
 
Back
Top