使用VBA访问Outlook中的文件夹 [英] Accessing folders in Outlook with VBA

查看:552
本文介绍了使用VBA访问Outlook中的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下内容将邮件移动到Outlook中的文件夹.

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)    

一切正常.如您所见,该文件夹位于Livelink中.而且Livelink服务器的响应速度实际上很慢,我对此无能为力.

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.

我担心的是使用.Folders()这么多次,而做.Folders("Livelink/root/folder1/folder2/")之类的东西要快得多.但这显然不起作用,并且因为.Folders命令每次都需要ping Livelink服务器,所以实际上只需要花费整整10秒钟的时间来执行这一行代码(文件夹越深,到达的时间就越长它).

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

还有其他方法可以直接访问Outlook中的特定文件夹来移动邮件吗?我知道每个文件夹(甚至是Livelink中的文件夹)都有某种Outlook ID,但是我看不到任何使用它的方法.我已经尝试了以下方法,但仍无法正常工作:

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)

在执行GetFolderfromID()时,这给我一个错误. var target实际上是我要将邮件复制到的文件夹的EntryID.

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.

推荐答案

根据官方文档,没有比您正在做的更好的方法了,除非您需要多次查找该文件夹.

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.

MSDN建议的选项是从文件夹路径获取文件夹对象,但这基本上可以完成您已经在做的事情.

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.

问题是文件夹对象仅表示在文件夹树的一级上代表特定子集中的所有可用Outlook文件夹."(强调)

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)

可能的解决方法是使用 NameSpace.GetFolderFromID ,但是为此您需要知道EntryID,可能还需要知道StoreID,这通常意味着您无论如何都要首先找到该文件夹​​.但是您可以保存EntryIDStoreID以便将来立即调用.

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.

如果您想深入研究使用EntryIdStoreID,请参见

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

这篇关于使用VBA访问Outlook中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆