2016-09-19 100 views
-1

你好,我有這個完美的代碼,我發現。它檢查新消息,並且只在日期和時間中添加自定義列。它非常適合按收到然後從收信人分組。Outlook VBA多個Acounts運行腳本

但它只適用於我的默認帳戶,可以使用多個帳戶嗎?

Private Sub Application_Quit() 
    Set myInbox = Nothing 
End Sub 

Private Sub Application_Startup() 
    Set myInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items 

End Sub 

Private Sub myInbox_ItemAdd(ByVal Item As Object) 
    Item.UserProperties.Add "DateReceived", olDateTime 
    Item.UserProperties.Item("DateReceived") = DateValue(Item.ReceivedTime) 
    Item.Save 
End Sub 
+0

請參閱此處:http://stackoverflow.com/questions/33953386/vba-to-select-mailbox-if-an-account-has-multiple-mailboxs – OpiesDad

+2

可能重複[獲取對其他收件箱的引用](http ://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox) – niton

+0

以及http://stackoverflow.com/questions/26274516/vba-get-email-from-non-default-inbox和http://stackoverflow.com/questions/6849068/get-inboxes-from-outlook – niton

回答

0

現有的代碼工作的默認收件箱文件夾,由於下面的代碼行:

Set myInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items 

相反,你需要遍歷所有的商店在配置文件中調用的的GetDefaultFolder方法Store類,它返回一個Folder對象,該對象表示商店中的默認文件夾,並且該參數的類型爲FolderType參數。該方法類似於NameSpace對象的GetDefaultFolder方法。區別在於此方法獲取與帳戶關聯的交付存儲的默認文件夾,而NameSpace.GetDefaultFolder返回當前配置的默認存儲的默認文件夾。

Namespace類的Stores屬性返回一個Stores集合對象,該對象表示當前配置文件中的所有Store對象。

最後,您可能會發現文章Working with Outlook Accounts, Stores, Folders and Items有幫助。