none
Is there a way using VBA in Outlook to get the last updated date/time for a folder? RRS feed

  • Question

  • I have a couple of rules in Outlook that move emails with certain words in the Subject to sub-folders.  These emails are for failures notices for my production environment.  I also created a VBA script to check these folders for new items and let me know that I have failures that need to be looked at.  I want to have this script run when Outlook starts.  I have tried putting the code in Application_Startup() and Application_MAPILogonComplete().  But the script runs before the folders are updated so therefore I do not receive the notices I should.

    Is there a way in VBA to either have this script run after all folders are updated or to get the last modified date/timestamp of the folders so I can create a loop to wait to execute the script until after the folders are updated?

    Thanks you!

    Wednesday, June 20, 2012 5:00 PM

Answers

All replies

  • There is no event that fires when cached folders are updated, but you can certainly have an Items.ItemAdd event on the folder.

    You can also find the newest item in the folder by sorting the Items collection of that folder appropriately (e.g. sort on CreationTime) and then accessign the first item in the collection.


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

    Wednesday, June 20, 2012 5:58 PM
  • I guess what bugs me is if I am in the folder and I go to the Folder Ribbon and click the Folder Properties, I can see under the Sychronization tab the last time the folder was synced.  If I can see it there I would have thought that it would be available in VBA.

    Neither the Items.ItemAdd event or searching for the newest item in the folder will work.  I do not always receive a mail item for the folder.  I only get one if I have a failure.  That is why I want to check for the last update date/time.  If the folder is current then I know I had no failures.  If the folder has not been updated then I know I have to wait to run my script until the folder has been updated.

    Wednesday, June 20, 2012 6:33 PM
  • That information is not programmatically exposed; at least it is not documented.

    I am not sure why Items.ItemAdd event or searching for the newest item in the folder won't work. It is the last sync date that won't work.

    Why does it matter when the folder was synchroniuzed? What matters is that you have a new (unprocessed by your code) message in that folder.


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

    Thursday, June 28, 2012 9:44 PM
  • Well, when I startup Outlook my macro runs before the folder is updated.  therefore if I have failed jobs I am not notified.

    I thought if I could check the synchronization time of the folder, I could have my macro loop and just perform DoEvents() until the folder is updated and then check the contents.

    Tuesday, July 3, 2012 4:14 PM
  • If Outlook starts synching the new messages after your code is initialized, Items.ItemAdd event on that folder should work fine.


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

    Thursday, July 5, 2012 2:43 PM