【发布时间】: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 创建该方法。