【问题标题】:VBScript to create an outlook ruleVBScript 创建 Outlook 规则
【发布时间】:2017-08-29 02:47:25
【问题描述】:

我正在尝试创建一个可以分发的vbscript,以便为运行它的每个用户创建一个 Outlook 规则。

我有一些代码(如下),但是我发现我无法通过 VBS 使用 Actions.Run(“VBA 代码”)创建规则。我需要一个规则,这样每当收到来自"test@test.com" 的电子邮件时,就会显示msgbox,用户必须单击“确定”。

通过我的研究表明,VBA 可能以某种方式能够在VBS 文件中实现,但我找不到太多关于它的信息。

我要运行的 VBA 是:

Sub newmsg(item As Outlook.MailItem)
 MsgBox "You have an urgent message: " & item.Subject
End Sub

VBS 是:

'--> Create some constants
Const RULE_NAME = "Urgent Message"  '<-- Edit the name of the rule
Const olRuleReceive = 0

'--> Create some variables
Dim olkApp, olkSes, olkCol, olkRul, olkCon, olkAct

'--> Connect to Outlook
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
olkSes.Logon olkApp.DefaultProfileName

'--> Get the rules collection
Set olkCol = olkSes.DefaultStore.GetRules()

'--> Create a new receive rule
Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)

'--> Set the rule's condition to look for a specific word in the subject
Set olkCon = olkRul.Conditions.From
With olkCon
    .Enabled = True
    .Recipients.Add ("email address here")
    .Recipients.ResolveAll
End With


'--> Set the rule's action
Set olkAct = olkRul.Actions.Run("Project1.newmsg")
With olkAct
    .Enabled = True
End With

'--> Save the rule
olkCol.Save False

'--> Disconnect from Outlook
olkSes.Logoff
Set olkCon = Nothing
Set olkAct = Nothing
Set olkRul = Nothing
Set olkCol = Nothing
Set olkSes = Nothing
Set olkApp = Nothing

'--> Terminate the script
WScript.Quit

【问题讨论】:

  • 您希望 newmsg 方法存在还是希望使用 VBS 创建该方法?
  • 嗨 Eric,希望使用 VBS 创建该方法。

标签: vba vbscript outlook


【解决方案1】:

唯一受支持的修改 VBA 项目的方法是使用 Visual Basic Extensibility 接口为 VBA 编辑器开发插件。

如果您需要创建一个执行自定义操作的规则,那么我建议您构建一个 Outlook 加载项来处理传入的电子邮件并在加载项的代码中执行操作,而不是依赖于可能的 VBA 方法或者可能不存在。

【讨论】:

  • 谢谢埃里克。我将开始研究创建 Outlook 加载项
猜你喜欢
  • 2016-12-27
  • 1970-01-01
  • 1970-01-01
  • 2012-06-21
  • 2016-09-28
  • 2018-07-22
  • 1970-01-01
  • 2010-11-15
  • 2018-02-02
相关资源
最近更新 更多