How can I get access to Microsoft.Office.Interop.Outlook.OlRuletype (or other namespaces) in WSH, JScript

StackOverflow https://stackoverflow.com/questions/21929876

  •  14-10-2022
  •  | 
  •  

Pregunta

I have written the WSH script using JScript. I am currently getting in stuck that I cannot refer to the namespace "Microsoft.Office.Interop.Outlook.OlRuletype". The source code is shown below:

var olApp = WScript.CreateObject("Outlook.Application");
var olNS = olApp.Session;
var folder = olNS.Folders("myname@mailserv.com").Folders("Inbox");

CreateRule(olNS);
ShowInbox(folder);

function CreateRule(olNS)
{
    var rules = olNS.DefaultStore.GetRules();

    //Error occurred here..
    //Error:  'Microsoft' is undefined
    //Code:   800A1391
    //Source: Microsoft JScript runtime error
    var opt = Microsoft.Office.Interop.Outlook.OlRuletype.olRuleReceive;

    var newRule = rules.Create("Testing", opt);
}

function ShowInbox(folder)
{
    if (olApp.Explorers.Count == 0)
    {
        folder.Display();
    }
}

Am I correctly referring to the namespace? Thank you for every suggestion in advance.

¿Fue útil?

Solución

Windows Script Host and JScript don't know anything about constants in type library enumerations. You need to explicitly define these constants in your script:

var olRuleReceive = 0;
var olRuleSend = 1;


So, have I need to find out about the number of constant value myself? Do you have some way to search that value from MSDN document?

You have several options:

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top