excel - VBA: Search email in non default outlook inbox? -


i using following vba code checks emails specific subject heading.

the problem checks default outlook inbox folder when need check inbox of other email account.

can please show me how this?

sub macro1()    set olapp = createobject("outlook.application")         dim olns outlook.namespace        dim fldr outlook.mapifolder        dim myitem outlook.mailitem        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 olmail = mytasks.find("[subject] = ""new supplier request: ticket""")     if not (olmail nothing)          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.delete   next    call macro2    else   msgbox "there no new supplier requests."   end if end sub 

instead of iterating through folder items in outlook:

 each myitem in mytasks     if myitem.attachments.count <> 0         each myattachment in myitem.attachments 

i'd suggest using find/findnext or restrict methods of items class. may consider using using advancedsearch method of application class. take @ following articles sample code illustrates how use them in code:


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 -