outlook - VBA to move email folders & contents -
i stumped work on script move email folder (& contents) different parent folder. folder no under parent inbox. have basic, self-taught understanding of vba.
eg. thisoutlooksession/[foldera] move thisoutlooksession/inbox/[foldera]
ive found lots of examples move emails not folders.
thanks in advance assistance.
edit:
private sub importfolder() <br> ''''''''' '' assume example im not overloading code have created csv im drawing data from, opened in excel & macro running outlook ''''''''' dim xlwkb object ' workbook dim xlsht object ' worksheet set xlsht = xlwkb.worksheets(1) 'set active being first worksheet dim irow integer dim chilcol integer dim parentfoldername irow = 1 'set start row1 chilcol = 1 'set start cola 'set parent static nomination in head macros while xlsht.cells(irow, 1) <> "" 'while parent not blank if chilcol <= 1 set objparentfolder = session.getdefaultfolder(olfolderinbox) else parentfoldername = xlsht.cells(irow, chilcol - 1) 'set parent previous column set objparentfolder = objparentfolder.folders(parentfoldername) end if 'set name new folder newfoldername = xlsht.cells(irow, chilcol) on error resume next '''''''''''''''''''''''''''''''''''''' dim objnewfolder outlook.folder ''''''''''''''''''''''''''''''''''''''' if newfoldername = "inbox" newfoldername = nothing end if 'if parentfolder = newfoldername ' set objnewfolder = objparentfolder.folders(newfoldername) '' unsure - have archive email folder on same hierarchy inbox '' due how mobile outlook displays folders. part of code should check if '' parent folder new folder mapped in move folder in archive inbox\subfolder if objnewfolder.parent = "zarchive" , objnewfolder.parent = parentfoldername objnewfolder.moveto session.getdefaultfolder(olfolderinbox) end if 'if no issues, create folder if objnewfolder nothing 'if no value set objnewfolder = objparentfolder.folders.add(newfoldername) 'add folder end if ' make new folder parent set objparentfolder = objnewfolder if xlsht.cells(irow, chilcol) = "" ''unless blank irow = irow + 1 'new row chilcol = 0 'reset childcolumn end if chilcol = chilcol + 1 ' move next nesting column set objnewfolder = nothing 'required reset new folder name wend xlwkb.close xlapp.quit set xlwkb = nothing set xlapp = nothing set objparentfolder = nothing end sub
you can use folder.moveto method moves folder specified destination folder.
sub movefolder() dim mynamespace outlook.namespace dim myfolder outlook.folder dim mynewfolder outlook.folder set mynamespace = application.getnamespace("mapi") set myfolder = mynamespace.getdefaultfolder(olfoldercontacts) set mynewfolder = myfolder.folders.add("my test contacts") mynewfolder.moveto mynamespace.getdefaultfolder(olfolderinbox) end sub
you may find getting started vba in outlook 2010 article helpful.
Comments
Post a Comment