![]() |
#2
|
||||
|
||||
![]()
You can loop through the folders collection below any start folder and move the message to that folder. The following puts the selected message in the named folder ("Folder Name"), creating it as a subfolder of the start folder if not present. The macro prompts for the top level start folder.
Code:
Option Explicit Sub MoveMessage() Dim olMsg As MailItem Dim olFolder As Folder On Error Resume Next Set olMsg = ActiveExplorer.Selection.Item(1) GetFolder olMsg, "Folder Name" lbl_Exit: Set olMsg = Nothing Exit Sub End Sub Sub GetFolder(olItem As MailItem, strFolderName As String) Dim olNS As NameSpace Dim cFolders As Collection Dim olFolder As Outlook.Folder Dim StartFolder As Outlook.Folder Dim SubFolder As Outlook.Folder Dim bExists As Boolean Set cFolders = New Collection Set olNS = GetNamespace("MAPI") Set StartFolder = olNS.PickFolder cFolders.Add StartFolder Do While cFolders.Count > 0 Set olFolder = cFolders(1) cFolders.Remove 1 If UCase(olFolder.Name) = UCase(strFolderName) Then bExists = True Exit Do End If For Each SubFolder In olFolder.folders cFolders.Add SubFolder Next SubFolder Loop If Not bExists Then Set olFolder = StartFolder.folders.Add(strFolderName) End If olItem.Move olFolder lbl_Exit: Set olNS = Nothing Set StartFolder = Nothing Set cFolders = Nothing Set olFolder = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
cutemich | Word VBA | 1 | 05-09-2017 06:27 PM |
![]() |
vagabond | Word | 7 | 05-02-2017 03:24 PM |
Linking to a spreadsheet in the same folder without folder path | Jacky837 | Excel | 0 | 07-30-2016 05:07 AM |
![]() |
carlandtina02 | Excel Programming | 3 | 04-15-2016 01:47 PM |
How to find the path to the downloads folder when it is different for each user | CatMan | Excel Programming | 2 | 12-07-2012 09:59 PM |