如何从VBScript访问Outlook规则

时间:2019-04-18 15:39:08

标签: vbscript outlook

我正在尝试使用VBScript通过任务计划程序启用规则。我可以使用其他脚本来创建文件夹,甚至创建电子邮件,但是尝试访问“规则”时,该脚本不起作用。如何获得Outlook规则Shelby_outlook启用?

这是针对使用所有默认设置的基本配置的Outlook 2016。

仅作比较,这有效...

 Option Explicit
 Dim myOutlook
 Dim myNameSpace
 Dim myFolder
 Dim myNewFolder

     set myOutlook = CreateObject("Outlook.Application")
     Set myNameSpace = myOutlook.GetNamespace("MAPI")
     Set myFolder = myNameSpace.GetDefaultFolder(6) '6 is the value of olFolderInbox
     Set myNewFolder = myFolder.Folders.Add("Tod")  
  Wscript.Quit

这是我用来启用规则的实际代码,但是它不起作用...

Option Explicit
Dim olRules, olRuled, olRule, olNamed


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

    '--> Find Rule
    Set olRule = olRuled.DefaultStore.GetRules()
    Set olNamed = olRule.Item("Shelby_outlook") 

    '--> Enable Rule
    With olNamed
        .Enabled = True

    end With


    '--> Disconnect from Outlook
    olRuled.Logoff

Set olRule = Nothing
Set olRules = Nothing
Set olRuled = Nothing
Set olNamed = Nothing


'--> Terminate the script
WScript.Quit

WScript.echo olNamed打印出

  

Shelby_outlook

它应该启用...

0 个答案:

没有答案