使用 vba 宏为每个帐户执行 Outlook 规则

问题描述 投票:0回答:1

我正在尝试编写一个 vba 代码,该代码将在我所有 Outlook 帐户的“垃圾邮件”文件夹中执行特定规则。

目前我有这个(在互联网上找到),但它似乎只适用于 2 个连接帐户中的 1 个:

Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim ruleList As String
Dim fldJunk As Outlook.Folder
Dim oAccount As Outlook.Account


For Each oAccount In Outlook.Application.Session.Accounts

        ' get default store (where rules live)
        Set st = Application.Session.DefaultStore
        ' get rules
        Set myRules = st.GetRules
        ' get Junk e-mail folder
        Set fldJunk = st.GetDefaultFolder(olFolderJunk)

        ' iterate all the rules
        For Each rl In myRules
            If rl.Name = "Junk Cleaner" Then
                rl.Execute ShowProgress:=True, Folder:=fldJunk
                ruleList = ruleList & vbCrLf & rl.Name
            End If
        Next

Next

我的印象是,即使我“为每个帐户”创建一个循环,我也不确定循环的主体是否考虑了帐户的更改...

提前致谢! :)

我尝试实现一个循环:

For Each oAccount In Outlook.Application.Session.Accounts

但是好像没效果 仅适用于我在 Outlook 中所有已连接帐户中的第一个帐户:(

vba outlook rules
1个回答
0
投票

您始终处理

返回的同一家商店
Set st = Application.Session.DefaultStore

将该行替换为

Set st = oAccount.DeliveryStore
© www.soinside.com 2019 - 2024. All rights reserved.