【问题标题】:Create/Copy (this rule on all accounts) outlook using vba使用 vba 创建/复制(所有帐户上的此规则)outlook
【发布时间】:2018-12-02 13:43:52
【问题描述】:

有没有办法使用vba代码将一个帐户的outlook规则复制到另一个帐户。我在互联网上进行了研究,但没有发现任何与我的问题相关的东西,请帮助我。参考任何链接。我不是 vba 专家。我会非常感谢你。

【问题讨论】:

    标签: vba outlook outlook-2016


    【解决方案1】:

    Import or export a set of rules

    您可以通过编程方式创建规则。 Rules 类的Create 方法创建一个Rule 对象,其名称由Name 指定,规则类型由RuleType 指定。添加规则的RuleType 参数确定可以与Rule 对象关联的有效规则操作、规则条件和规则异常条件。集合中添加规则时,新规则的Rule.ExecutionOrder为1。集合中其他规则的ExecutionOrder加1。

     Sub CreateRule() 
       Dim colRules As Outlook.Rules 
       Dim oRule As Outlook.Rule 
       Dim colRuleActions As Outlook.RuleActions 
       Dim oMoveRuleAction As Outlook.MoveOrCopyRuleAction 
       Dim oFromCondition As Outlook.ToOrFromRuleCondition 
       Dim oExceptSubject As Outlook.TextRuleCondition 
       Dim oInbox As Outlook.Folder 
       Dim oMoveTarget As Outlook.Folder 
       'Specify target folder for rule move action 
       Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox) 
       'Assume that target folder already exists 
       Set oMoveTarget = oInbox.Folders("Dan") 
       'Get Rules from Session.DefaultStore object 
       Set colRules = Application.Session.DefaultStore.GetRules() 
       'Create the rule by adding a Receive Rule to Rules collection 
       Set oRule = colRules.Create("Eugene's rule", olRuleReceive) 
       'Specify the condition in a ToOrFromRuleCondition object 
       'Condition is if the message is sent by "DanWilson" 
       Set oFromCondition = oRule.Conditions.From 
       With oFromCondition 
        .Enabled = True 
        .Recipients.Add ("Eugene Astafiev") 
        .Recipients.ResolveAll 
       End With 
    
       'Specify the action in a MoveOrCopyRuleAction object 
       'Action is to move the message to the target folder 
       Set oMoveRuleAction = oRule.Actions.MoveToFolder 
       With oMoveRuleAction 
        .Enabled = True 
        .Folder = oMoveTarget 
       End With 
    
       'Specify the exception condition for the subject in a TextRuleCondition object 
       'Exception condition is if the subject contains "fun" or "chat" 
       Set oExceptSubject = _ 
       oRule.Exceptions.Subject 
       With oExceptSubject 
        .Enabled = True 
        .Text = Array("fun", "chat") 
       End With 
    
       'Update the server and display progress dialog 
       colRules.Save 
     End Sub 
    

    【讨论】:

    • Astagiev 我们可以将规则从一个帐户复制到另一个帐户吗?我不想使用导入导出功能。
    • 你说的是客户端规则吗?
    • 是的,我有 1 个包含服务器端规则的交换帐户,我想在需要时通过 VBA 模块将所有服务器端规则复制到我的其他本地 Outlook 帐户?
    • Outlook 对象模型不提供任何服务器端规则。
    • 好的,请帮助我使用 VBA 代码将一个帐户客户端规则复制到所有客户端规则
    猜你喜欢
    • 2018-07-22
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 2015-04-12
    • 2019-02-08
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    相关资源
    最近更新 更多