首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果帐户有多个邮箱,则使用VBA选择邮箱

如果帐户有多个邮箱,则使用VBA选择邮箱
EN

Stack Overflow用户
提问于 2015-11-27 16:44:13
回答 2查看 17.9K关注 0票数 4

这是我的要求。

我在OUTLOOK中配置了多个帐户。1) 1@email.com (只有一个邮箱) 2) 2@email.com (有多个邮箱。例如: Unix box、Windows Box、Mac box)

这里我的第二个电子邮件帐户有自己的邮箱,并链接到多个邮箱,如UNIX,Windows等。每个邮箱都有自己的收件箱和子文件夹。

现在我需要在Unix邮箱(收件箱)中选择一个文件夹,然后运行代码在文件夹旁边执行一些操作。

这是我的资料

代码语言:javascript
复制
For Each oAccount In Application.Session.Accounts
If oaccount ="1@email.com" then
Set folder = ns.GetDefaultFolder(olFolderInbox) ' here it selects the inbox folder of account.
For each item in folder.items
Code goes here
next
end if
next

这适用于单个邮箱帐户,但当我对多个邮箱帐户执行此操作时,它不起作用。

任何帮助都将不胜感激。

EN

回答 2

Stack Overflow用户

发布于 2015-12-02 06:37:20

扩展了DanL的建议,循环通过ns.Folders,因为我不知道你是否理解它。

代码语言:javascript
复制
Option Explicit

Sub accTopFolder()

Dim oAccount As Account
Dim ns As Namespace
Dim fldr As folder
Dim item As Object
Dim inbx As folder

Set ns = GetNamespace("MAPI")

For Each oAccount In Session.Accounts

    Debug.Print vbCr & "oAccount: " & oAccount
    '
    For Each fldr In ns.Folders
    ' Shows all the names so you can replace "test"
        Debug.Print " top folder: " & fldr.name
        If fldr = "test" Then
            Set inbx = fldr.Folders("Inbox")
            'inbx.Display
            For Each item In inbx.Items
                Debug.Print "  item .Subject: " & item.subject
            Next
            Exit For
        End If
    Next
Next

Set inbx = Nothing
Set ns = Nothing

End Sub
票数 2
EN

Stack Overflow用户

发布于 2015-11-27 18:06:31

您可以使用AccountDeliveryStore属性来获取其收件箱。例如:

代码语言:javascript
复制
Dim ns As NameSpace
Set ns = Application.Session

Dim acc As Account
Dim f As Folder

For Each acc In ns.Accounts
    ... Preconditions here ...
    Set f = acc.DeliveryStore.GetDefaultFolder(olFolderInbox)
    ... Now, do some looping ...
Next
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33953386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档