3

在 Outlook 2007 中,我可以使用如下代码遍历邮件存储,包括 PST:

Dim stores As Outlook.stores
Set stores = objNamespace.stores
Dim store As Outlook.store

For Each store In stores
    MsgBox store.FilePath
Next

但是,在 Outlook 2003 中,Outlook.store 和 Outlook.stores 对象不存在。

Outlook 2003 中是否有等效对象?我可以使用什么其他方法来循环邮件存储?

谢谢你。

4

1 回答 1

4

Outlook 2003 的此示例代码将遍历高级邮箱并将某些属性打印到即时窗口。我根据您的要求选择了看起来最有用的属性。

Sub LoopThruMailboxes()

Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim mailboxCount As Long
Dim i As Long
Dim folder As Outlook.MAPIFolder

' get local namespace
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")

mailboxCount = olNS.Folders.count

For i = 1 To mailboxCount
  Set folder = olNS.Folders(i)

  Debug.Print folder.EntryID
  Debug.Print folder.StoreID
  Debug.Print folder.Name
  Debug.Print folder.FolderPath
Next i

End Sub

folder.Name是邮箱的名称,folder.StoreID是商店 ID(我不确定您所说的“商店文件路径”是什么意思,反正我没有看到任何相关的内容)。

这是一个函数化版本,它以数组的形式返回文件夹名称和存储 ID,您可以将其直接分配给列表框:

Function GetMailBoxInfo() As String()

Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim mailboxCount As Long
Dim i As Long
Dim folder As Outlook.MAPIFolder
Dim tempString() As String

' get local namespace
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")

mailboxCount = olNS.Folders.count

' size array accordingly
ReDim tempString(1 To mailboxCount, 1 To 2)

For i = 1 To mailboxCount
  Set folder = olNS.Folders(i)

  tempString(i, 1) = folder.Name
  tempString(i, 2) = folder.StoreID
Next i

  GetMailBoxInfo = tempString

End Function

前任:

ListBox1.List = GetMailBoxInfo
于 2011-11-08T16:26:28.180 回答