Moving messages from a subfolder

  • Thread starter Thread starter Mark E. Schill
  • Start date Start date
M

Mark E. Schill

I need a way to poll several folders when my local outlook client opens up
and move all messages to their respective folders on a local *.pst file. Can
anyone assist me in programming this?

Thanks,
Mark
 
I think I can help a little. I've got another thread going here on a related topic and am still having problems. But I think I'm farther along than you might be. Here's what I do:

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim mySrcRootFolder As Outlook.MAPIFolder
Dim mySrcRootFolderName as String
Dim myDestRootFolder As Outlook.MAPIFolder
Dim myDestSubFolder As Outlook.MAPIFolder
Dim iFolder As Outlook.MAPIFolder


1. Load the pst file using
AddStoreEx. I'm using olStoreUnicode for the second parameter. E.g.,
Set myNameSpace = myOlApp.GetNamespace("MAPI")
myNameSpace.AddStoreEx <Filesystem path to pst>, olStoreUnicode

2. Get the root folder name of the pst you just added. Getting that is a problem, though, if you don't know what it is and that's the issue in my other thread. Hopefully you just know what it is or you defined it, then you won't have the trouble I am.

3. I point my source folder object to this root folder of the PST.
Set MySrcRootFolder = MyNameSpace.Folders(MySrcRootFolderName)

4. I point my destination folder object to the root folder of my destination store (another PST or the Exchange Server store) the same way.

5. I iterate through the source folders and their items
For Each iFolder In mySrcFolder.Folders
For Each iItem in iFolder.Items
<code>
Next iItem
Next iFolder

6. When you find the item you want to move, set the destination folder (in my case I want it to be the same subfolder name as it is on the source store):
Set myDestSubFolder = myDestRootFolder(iFolder.Name)

7. Move the item (email, appointment, task, whatever)

iItem.Move myDestSubFolder

So far, my code only works if I only have one level of subfolders from the root. If any of my subfolders, though, also have subfolders I'm still having problems. I can get the item ok from the source pst using recursion, but I'm having troubles setting the folder paths for the destination. I would have expected a folder spec such as "Archive Folders\Inbox\Rick's Items" would be the say to specify the folder, but it doesn't seem to work and I can't seem to find any code examples where nested folders are dealth with. Maybe you have a suggestion.

Another thing to keep in mind that caused me some grief. If you are iterating through different types of items, remember that they may not have the same property names. In my case I'm finding items based on the date they were created. If the item is an email item, I need to use the "ReceivedTime" property, but if it's a Task Request, I need to use the "CreationTime" property. I would love it if all the items had a property with the same name that held the date I'm looking for, but I couldn't find any. So, I need, instead, to do a Select Case for each item type and use the appropriate property to see if it an item of interest to me. This part has been a real pain because I've been unable to find anything that lists all of the item types and the property name for those item types. F2 doesn't seem to list them all in a way that helps. I've just been doing the best I can, when my program stops because of an unknown item type, I just modify the code and add that item type. Fortunately, this is just play code I'm writing to organize my PSTs, so I don't mind being a little sloppy :-)

I'd be happy to send you a copy of my "sloppy" source code, but I don't want to post it here as I've suffered enough humiliation already :-) I generally pride myself in writing clean, clear, maintainable, and efficient code; this code is not an example of that :-). If you want it, please send me an email. My email address is (e-mail address removed) and I'm not worried if that address gets spammed.

Good luck. I'd appreciate hearing anything interesting you learn.

Rick
 
Back
Top