outlook vba - VBA - Dynamically set variable from array -
i'm creating macro outlook processes email items in designated folder gets triggered rule. sub
routine sets sub-folder this:
set olsub = olmailbox.folders("customer").folders("requests").folders("open")
i able use sub
many different folders, difference being line above.
my question how can pass array sub
set olsub
chained .folders()
statement? keeping in mind number of sub-folders , therefore array vary in length.
the desired outcome this:
sub mainroutine(olarr) ... ' sort of magic loop sets olsub olarr until, olsub = olmailbox.folders("customer").folders("requests").folders("open") ... end sub sub otherroutine() olarr = array("customer", "requests", "open") mainroutine olarr end sub
try this:
public function getfolder(fromfolderpath string) mapifolder dim arrpaths() string arrpaths = split(fromfolderpath, "\") dim integer dim objloopfolder mapifolder dim objns namespace set objns = application.getnamespace("mapi") set objloopfolder = objns.folders("my mailbox name") = 0 ubound(arrpaths) set objloopfolder = objloopfolder.folders.item(arrpaths(i)) next set getfolder = objloopfolder end function
it takes folder path, e.g. my mailbox name\first folder\sub folder 1\sub folder 2
, if need take array, can modify it.
Comments
Post a Comment