此示例代碼爲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(我不知道你所說的「存儲文件路徑」是什麼意思,我沒看到什麼無論如何看起來都是相關的)。
這裏有一個functionized版本,返回文件夾的名稱和店鋪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
是否有具體的你正在做的事情每個商店?您可以遍歷Outlook 2003中的每個郵箱,但取決於您在做什麼,它可能會也可能不會。 – JimmyPena
首先,我想用存儲顯示名稱,存儲文件路徑和存儲ID填充列表框。用戶將從列表中選擇一家商店並點擊一個按鈕。這會將StoreID保存在一個字符串變量中。然後,我將使用NameSpace.GetItemFromID方法來獲取MailItem。最後,我將調用MailItem.Display。 –