VBA Outlook Item Move -


i have hacked following piece of code in outlook 2007 vba judicious copying of others code sites this. not programmer, apologies in advance obvious failings.

the routine monitors email on way out , asks user want file outgoing email. looks emails indentical conversation topic , files in same place.

all works fine purposes, except bit files identical items. colitems returns correct number of emails in inbox , colfiltered returns correct number of emails identical conversation topic. unfortunately, if there are, say, 5 items in colfiltered, moves 3 of them, leaving 2 in inbox have manually filed.

am missing obvious.?

any appreciated.

julian

private sub application_itemsend(byval item object, cancel boolean) dim intres integer dim strmsg string dim save_mess dim await_replies_fldr folders dim objns namespace dim objfolder mapifolder  'variables select linked emails bit dim ofolder outlook.mapifolder dim colitems outlook.items dim colfiltered outlook.items dim oitem object  on error resume next  set outgoingmail = item  'delete sent meeting requests. if item.class = olmeetingrequest      'just move deleted items folder     set objns = application.getnamespace("mapi")     set objfolder = objns.getdefaultfolder(olfolderdeleteditems)     set item.savesentmessagefolder = objfolder  end if  'put dilaog choose save folder location if item.class = olmail   ' act on mail messages      set objns = application.getnamespace("mapi")     set objfolder = objns.pickfolder ' put dialog box pick save folder          save_mess = msgbox("move related emails.?", 4, "related emails.?")          if save_mess = 6 ' if yes              'to pick , file related messages in inbox same conversation topic             set ofolder = application.session.getdefaultfolder(olfolderinbox)             set colitems = ofolder.items             'filter conversation same selected item             set colfiltered = colitems.restrict("[conversationtopic]='" & item.conversationtopic & "'")                   each oitem in colfiltered                     ' msgbox oitem.creationtime 'debug message                      oitem.unread = false ' mark read                     oitem.move objfolder ' move selected folder                   next oitem         end if          if not objfolder nothing ' check objfolder has been populated                 if isindefaultstore(objfolder) ' checks location valid place store email                       set item.savesentmessagefolder = objfolder ' save current item in selected folder                    end if         end if      'reset objects     set objfolder = nothing     set objns = nothing  end if  end sub 

for each not work in move nor delete. index resets. try this.

iterating through outlook appointment items

step backwards when moving or deleting.

for = colfiltered.count 1 step -1


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -