2016-09-19 102 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有帮助。