excel vba - Scope using AdvancedSearch method for entire mailbox -


so new dasl queries, , have been scouring web trying find out how use them correctly. trying through outlook folders mail items matching parameters, , save attachment... pretty simple.

i am, unfortunately having issue code, don't know how reference scope go through folders, custom folders.

below code (i realize of statements wrong), appreciated. have performed due diligence these problems, can't find resources answer question, why i'm posting here. answers or references answers appreciated.

sub testing()  dim myolapp new outlook.application dim scope string dim filter string dim rsts results dim advancedsearch outlook.search  blnsearchcomp = false  'i want search entire mail account including normal folders inbox , sent custom folders. 'but doesn't work. ideas? scope = "'fakeexample123@outlook.com'" 'filter assignment statement has been excluded  set advancedsearch = myolapp.advancedsearch(scope, filter, true, "test")    while blnsearchcomp <> true     if advancedsearch.results.count > 0         blnsearchcomp = true     end if wend  set rsts = advancedsearch.results  x = rsts.count 1 step -1     rsts.attachment.item(x).saveasfile project next  end sub 

please let me know if additional information needed, , again, help!!! =)

ps: edit tip byron

well, know isn't best solution, have come following code make list of of parent folders, loop can used advanced search method iterate list. not fastest possible code, should not slow.

sub main() 'establishes connections dim myolapp new outlook.application dim objns outlook.namespace dim myfolder outlook.mapifolder set objns = myolapp.getnamespace("mapi") 'pick highest folder level original folder set myfolder = objns.folders("faxe.example123@outlook.com")  call processfolders(myfolder)  end sub  sub processfolders(myfolder)  're establish connections dim myolapp new outlook.application dim objns outlook.namespace dim objfolder outlook.mapifolder set objns = myolapp.getnamespace("mapi") 'set collection set x = new collection  each objfolder in myfolder.folders 'add parent folder names collection 'advanced search method handle subfolders 'can use recursive call here subfolders though     x.add objfolder.name next   set objns = nothing set myfolder = nothing set myolapp = nothing  end sub 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -