View Full Version : Moving Subfolders to anothr main folder
Kovenna
10-28-2015, 02:45 AM
I have a lot of folders and subfolders under my inbox in Outlook 2010.
I have about 60 subfolders linked to an upper level folder called "IT Support Calls". These are now finished so I need to move them to another upper level folder called "Completed Support Calls".
How could I do that in Outlook VBA? (I need prompts for source folder and destination folder).
Please note that I want to move folders and their contents, not just emails.
Many thanks
gmayor
10-28-2015, 06:26 AM
The following will prompt twice. First for the source folder, second for the target folder. It will then move all the sub folders from the source folder to the target folder
Sub MoveFolders()
Dim olNS As Outlook.NameSpace
Dim olSourceFolder As Outlook.Folder
Dim olTargetFolder As Outlook.Folder
Dim olSubFolder As Outlook.Folder
Dim i As Long
Set olNS = GetNamespace("MAPI")
Set olSourceFolder = olNS.PickFolder
Set olTargetFolder = olNS.PickFolder
For i = olSourceFolder.folders.Count To 1 Step -1
Set olSubFolder = olSourceFolder.folders(i)
olSubFolder.MoveTo olTargetFolder
Next i
lbl_Exit:
Set olNS = Nothing
Set olSourceFolder = Nothing
Set olTargetFolder = Nothing
Set olSubFolder = Nothing
Exit Sub
End Sub
Kovenna
10-28-2015, 06:44 AM
Thanks Graham - I'll insert that code and try it out :)
Kovenna
10-28-2015, 06:57 AM
Hi Graham,
Yep - this does what it says on the can. Superb thanks.
However, what if I have the situation where the upper level folder has say 200 subfolders, and I want to move say 100 of them to another folder?
Thanks
gmayor
10-28-2015, 11:13 PM
You would have provide some means to identify to the macro, whether each folder is to be moved as it is processed by the loop. How else would the macro know which are to be moved and which are to stay?
Kovenna
10-29-2015, 02:29 AM
Thanks Graham - good question.
Hmmm - I tried selecting several folders at once by using normal list selection mechanics but this does not work.
I think that the above will never be possible. Oh well, I least I asked the question ;-)
Thanks once again for your time.
gmayor
10-29-2015, 05:18 AM
No - You have to process the folders one at a time. You could put a confirmation prompt for each folder before deleting but with many folders that would soon become tedious. You could also choose to delete all with names that begin with (say) a certain letter (or letters), but without some ready means to identify them you are stuck with all or nothing.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.