MS outlook 2016 VBA - Application.ActiveExplorer.CurrentFolder - 似乎不起作用(在 OL2007 中起作用)

MS outlook 2016 VBA - Application.ActiveExplorer.CurrentFolder - 似乎不起作用(在 OL2007 中起作用)

几年前,我将一些特定的 VBA 代码复制到 Outlook 2007 中。它会在我选择的当前文件夹上运行我的规则。公司刚刚升级到 Outlook 2016(Office 365),虽然保留了 VBA 代码(在“ThisOutlookSession”中),但它不再起作用。

是否存在一些不再受支持的 VBA 代码?

Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim runrule As String
Dim rulename As String

rulename = "DBLP RULE"

Set st = Application.Session.DefaultStore

Set myRules = st.GetRules
Set cf = Application.ActiveExplorer.CurrentFolder
For Each rl In myRules

If rl.RuleType = olRuleReceive Then

If rl.Name = rulename Then
rl.Execute ShowProgress:=True, Folder:=cf
runrule = rl.Name

End If
End If
Next

Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub

我也试过

Set st = Application.Session.Stores(1)

因为我看到其他人也遇到了 DefaultStore 的问题。但这并没有解决它。

我也尝试明确说明规则名称:

If rl.Name = "DBLP RULE" Then

再次,这并没有使它发挥作用。

答案1

事实证明代码没有问题。虽然我确实更改了宏安全设置以允许宏运行(安装 Outlook 2016 后),但在重新启动 Outlook 后它并没有生效。我又重新启动了几次,它就生效了。

有趣的是,我没有收到提示宏已被禁用的弹出窗口。

问题现已解决。

相关内容