I have the following structure in my Outlook Public Folders.
-Public Folders
--1001_RandomProject
--1002_AnotherProject
--1003_Yetanotherproject
...
and so on, basically there's a couple of thousand(!) subfolders each corresponding to a project and prefixed with the project number.
Now I'm trying to create a Macro which will allow a user to select a number of mail items, enter the project number through an Inputbox and then move these mail items automatically to the subfolder corresponding to the project number.
All of this works, but in the current implementation I'm looping through all the subfolders of the Public Folders and comparing the entered project number to the first 4 characters of the folder name, to see if they match, and then move the mail items to the folder.
As you can imagine with thousands of subfolders, this tends to go quite slowly. So my question is: is there another way to select the correct folder without looping through all of them (sort of using a mask like 'find me a folder beginning with 1001*).
The simplified part of the "find the folder" code
Sub verplaatsen()
Dim Boodschap, Titel, Standaard
Dim ProjectNumber As String
Dim NrOfFolders as Integer
Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim FolderName as String
Boodschap = "Enter project number"
Titel = "Move mail"
Standaard = "0000"
ProjectNumber = InputBox(Boodschap, Titel, Standaard)
Set objOutlook = Application
Set objNamespace = objOutlook.GetNamespace("MAPI")
NrOfFolders = objNamespace.Folders(3).Folders(12).Folders.Count
I = 2
Do
FolderName = objNamespace.Folders(3).Folders(12).Folders(I).Name
If Left(FolderName, 4) = ProjectNumber Then
Else
I = I + 1
End If
Loop Until I = NrOfFolders Or Left(FolderName, 4) = ProjectNumber
MoveMail (I)
End Sub