本文介绍了如果帐户有多个邮箱,则 VBA 选择邮箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的要求.

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

I have multiple accounts in my OUTLOOK configured.1) [email protected] (only one mailbox)2) [email protected] (Multiple mailbox's are there. ex: Unix box, Windows Box, Mac box)

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

Here my 2nd email account has its own mailbox and linked to multiple mailbox's like UNIX, Windows etc. Each Mailbox has its own inbox and sub folders.

现在我需要在 Unix 框(收件箱)中选择一个文件夹并运行代码在文件夹旁边做一些事情.

Now i need to select a folder in Unix box (inbox) and run the code to do something in side the folder.

这是我所拥有的

For Each oAccount In Application.Session.Accounts
If oaccount ="[email protected]" 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

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

This works fine for single mailbox account, but when i do this for multiple mailbox account , it doesn't work.

任何帮助将不胜感激.

推荐答案

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

Expanding on DanL's suggestion to loop through ns.Folders as I cannot tell whether you understood it.

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

这篇关于如果帐户有多个邮箱,则 VBA 选择邮箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 06:32