vba - How can I trigger an event when multiple items added at once to Outlook Folder? -
i use event handlers in vba , outlook frequently. 1 of them 1 marks item deleted marked read.
private sub deleteditems_itemadd(byval item object) application_startup on error resume next item.unread = false end sub
declared via:
private withevents deleteditems outlook.items
and initialized in application_startup
as:
dim olnamespace outlook.namespace set olnamespace = olapp.getnamespace("mapi") set deleteditems = olnamespace.getdefaultfolder(olfolderdeleteditems).items
unfortunately, not affect items if delete multiple items @ once.
is there way can hijack process somehow? looked using _beforedelete event have set item correctly each time, if problem wouldn't exist anyways.
apparently wasn't clear - use case have when delete messages via delete key inbox, drafts, whatever.
you don't have to.
i curious question opened outlook , wrote code in thisoutlooksession
:
private withevents items outlook.items public sub setitems() set items = application.getnamespace("mapi") _ .getdefaultfolder(olfolderdeleteditems) _ .items end sub private sub items_itemadd(byval item object) dim mail mailitem on error resume next set mail = item err.clear on error goto 0 if not mail nothing msgbox mail.subject mail.unread = false end if end sub
then ran setitems
immediate pane, went inbox , deleted sms message - expected mail
nothing
. deleted single email, , got message mail's subject.
when selected 2 emails , hit delete, event fired once each selected email, saw 2 message boxes - works! :)
the outlook api doesn't seem offer event handle deletions @ once.
Comments
Post a Comment