4

I'm using the following to move a mail to a folder in Outlook.

Dim chemin() as String

chemin = Split(path, "/")
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.Folders("LiveLink").Folders("Livelink HQE").Folders("Entreprise").Folders(chemin(1)).Folders(chemin(2)).Folders(chemin(3))

myEntryID = myFolder.EntryID
myEntryID = myFolder.StoreID

objMail.Move myNameSpace.GetFolderFromID(myEntryID, storeID)    

Everything is actually working. As you can see, the folder is located into Livelink. And the Livelink server is actually quite slow to respond, and I can't do anything about it.

My concern is about using the .Folders() so many times while it would be A LOT faster doing something like .Folders("Livelink/root/folder1/folder2/"). But this isn't working obviously, and because the .Folders command needs to ping the Livelink server everytime, it actually takes a whole 10 seconds just to execute this line of code (and the deeper is the folder, the longer it is to reach it).

Is there any other way to directly access a specific folder in Outlook to move a mail? I know there is some kind of Outlook ID for each folders (even those in Livelink) but I don't see any way to make use of it. I've tried the following, but it's not working yet:

Dim folder As MAPIFolder
Dim myNameSpace As Outlook.NameSpace
Set myNameSpace = Application.GetNamespace("MAPI")
Set folder = myNameSpace.GetFolderFromID(target, Application.GetNamespace("MAPI").Folders("LiveLink").storeID)

This gives me an error when doing GetFolderfromID(). The var target is actually the EntryID of the folder I want to copy the mail to.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
dan
  • 3,439
  • 17
  • 54
  • 82
  • 1
    It's possible that target actuallly does not hold the EntryID, even though you think it should. The EntryID can change. Here's a quote from the last link I provided in my answer: It’s important to note that whenever an item is created in a folder, it is assigned a new EntryID. This means that the EntryID field changes if an item is moved to a different folder or if an item is exported and then imported (even to the same folder). http://msdn.microsoft.com/en-us/library/office/ff868618.aspx – Daniel Sep 27 '12 at 16:52
  • I've just noticed that I had the LivelinkID and not the OutlookID (EntryID), which isn't the same. I've tried with a valid EntryID (using OutlookSpy) and the `Set folder` works, but I get an error _Unable to move the element_ when doing the `objMail.move folder` now. – dan Sep 27 '12 at 17:02
  • All right, it just works now, for some reason I hadn't enough permissions to write on the destination folder, now it's okay. Well, thank you very much, I could have solved it myself I guess, but sometimes when we're stuck, we still need somebody to show us the obvious ;-) – dan Sep 27 '12 at 17:06

1 Answers1

4

Based on the official documentation, there is no better way than what you are doing, unless you will need to find the folder multiple times.

An option suggested by MSDN is to obtain the folder object from the folder path but this basically does the same thing you are already doing.

The problem is that the Folder Object only represents "represent all the available Outlook folders in a specific subset at one level of the folder tree."(emphasis added)

A possible work-around would be to use NameSpace.GetFolderFromID, but for that you would need to know the EntryID, and possibly the StoreID, which usually means you have to find the folder first anyway. But you could save the EntryID and StoreID for future immediate recall.

If you want to delve into using EntryIds and StoreIDs here is a developers reference on Working with EntryIDs and StoreIDs.

Daniel
  • 12,982
  • 3
  • 36
  • 60
  • Thank you very much for your answer. I feel kind of stupid right now because I do actually know the EntryID and as far as I know, the StoreID is always the same. The folders are actually created within another script. I will take a look at it and my problem might be solved. – dan Sep 27 '12 at 16:14
  • Just updated my original post with what I've been trying, it's not working yet. – dan Sep 27 '12 at 16:26