PDA

View Full Version : Refreshing folders from webmail in outlook



gr99
05-07-2008, 12:37 PM
I am using Outlook 2003 to access a web mail server and have written vba code to list all folders and the number of mail items within each folder. Generally, when I click on each folder it is refreshed and will report the correct number of mail items stored. Because I have nearly 50 folders I wrote some code in an attempt to have them refreshed automatically. I was given information that setting each folder to Application.ActiveExplorer.CurrentFolder was equivalent to clicking on each folder. The code is as follows:

Sub RefreshFolders()
Dim ol as Outlook.Application
Dim dfld as Object
Dim sfld as MAPIFolder
Set ol = New Outlook.Application
Set dfld =Application.GetNamespace("mapi").PickFolder
For each sfld In dfld.Folders
Set Application.ActiveExplorer.CurrentFolder = sfld
Next sfld
End Sub

This cycles through each folder but does not produce the required results in that the correct number of mail items is not displayed for folders that have changed. This I have proved by running the code, taking a listing then going back and manually selecting folders and taking another listing which then displays different results which could be higher or even lower (if I have deleted items within the web mail system).

One thing I wondered about was if enough time was given between refreshing each folder in the cycle and pehaps if I introduced a delay that might allow sufficient time for the information to be downloaded but I'm not sure how this would be acheived. Perhaps I barking up the wrong tree but I would welcome any advice which might help me achieve my goal.

Thanks.