使用 VBA 在 Outlook 2003 中循环 PST

发布于 2024-12-14 07:20:41 字数 356 浏览 2 评论 0原文

在 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 中是否有等效的对象? 我还可以使用什么其他方法来循环浏览邮件存储?

谢谢。

In Outlook 2007, I am able to loop through mails stores, including PSTs, using code like this:

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

For Each store In stores
    MsgBox store.FilePath
Next

However, in Outlook 2003, the Outlook.store and Outlook.stores objects do not exist.

Are there equivalent objects in Outlook 2003?
What other method might I use to loop through mail stores?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深缘浅 2024-12-21 07:20:41

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

This sample code for Outlook 2003 will loop through the high level mailboxes and print certain properties to the Immediate Window. I chose the properties that looked most useful based on your request.

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 is the name of the mailbox, folder.StoreID is the store ID (I'm not sure what you meant by "store file path", I didn't see anything that looked relevant anyway).

Here's a functionized version that returns folder name and store ID as an array, which you could assign directly to a listbox:

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

ex:

ListBox1.List = GetMailBoxInfo
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文