vba - search for emails with specific subject title IF UNREAD and save attachments into folder -


i using following vba code should search emails specific subject title i.e. subject 'test'

then if email unread save attachment email folder.

there may 1 or several emails subject test want unread emails subject test have attachments saved folder.

here code:

sub work_with_outlook()   set olapp = createobject("outlook.application")       dim olns outlook.namespace      dim fldr outlook.mapifolder      dim myitem object      dim myattachment outlook.attachment      dim long      dim olmail variant        set olapp = new outlook.application      set olns = olapp.getnamespace("mapi")      set fldr = olns.getdefaultfolder(olfolderinbox)      set mytasks = fldr.items    set unread = mytasks.restrict("[unread] = false")   set olmail = mytasks.find("[subject] = ""test""")   if not (olmail nothing) , unread.count = 0           each myitem in mytasks         if myitem.attachments.count <> 0             each myattachment in myitem.attachments             if instr(myattachment.displayname, ".txt")                 = + 1                 myattachment.saveasfile "\\uksh000-file06\purchasing\ns\unactioned\" & myattachment                 end if             next         end if      next   each myitem in mytasks myitem.unread = false next    msgbox "scan complete."    else   msgbox "there no new supplier requests."   end if  end sub 

this work degree, if have 1 email subject 'test' , unread script attachment email , save folder. however, if have 1 email subject 'test' read , email subject 'test' unread code won't work?

please can show me going wrong? in advance

it looks need combine both comditions single 1 , use find/findnext or restrict methods instance of items class contains items correspodning conditons. example:

 set resultitems = mytasks.restrict("[unread] = false , [subject] = ""test""") 

see enumerating, searching, , filtering items in folder information in msdn.

also may find sample code in following articles:


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -