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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -