Pregunta

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*).

¿Fue útil?

Solución

You could read the available folder names just once, and store their names in a local file. When the macro is run again, read that file into memory and use it to find the full folder name for a given project number quickly. Once you know the full name and folder path, navigating to the folder object should be easy (see here for a generic solution, utilizing Folders.item(foldername) ).

That file is a simple form of a cache or index. You might need to renew the cache after a while, or whenever a project number cannot be found, or when a project number is found in the cache, but not in the folder hierarchy any more. It will improve the search speed when the list of folder names does not change too often (at least, less often than you expect searches to happen).

Licenciado bajo: CC-BY-SA con atribución
scroll top