How to get text values of rules in MS Outlook using VBA? -


i trying text value(s) of conditions rule have set in ms outlook.

i have created rule named "testrule" condition based on text in message body (it must have text "zzz" in it) , condition based on text in message header (it must have text "aaa" in it). (of course, rule never run, test whether can read conditions in rule.) rule , conditions enabled.

here code using

dim olrules outlook.rules dim olrule outlook.rule  set olrules = application.session.defaultstore.getrules set olrule = olrules.item("testrule")  debug.print olrule.conditions.body.text debug.print olrule.conditions.messageheader.text 

however, both debug.print lines give error of "type mismatch".

how can read current value of conditions?

(i have checked , double-checked: there is rule named "testrule".)

gd drc,

i've putten more effort problem , think i've figured out why type mismatch.

you have added keywords "body" condition "messageheader" condition ? these individual entries added array, "olrule.conditions.body.text" array.

your below lines of code;

olrule.conditions.body.text debug.print olrule.conditions.messageheader.text 

are asking 'debug.print' mehtod print array, yet not know how that. not understand part of array print. depending on amount of entries have made identifier of each entry require identifier point unique array entry.

so:

  • olrule.conditions.body.text(0) point first entry in array.
  • olrule.conditions.body.text(1) point second entry in array.

there couple of ways solve coding issue:

  1. set breakpoint on line:

    olrule.conditions.body.text

so execution stops prior executing line of code. open 'locals window' (through view|locals window) , open olrule.text , see many array entries have added.

  1. amend code read per below

main subroutine

sub testrule() dim olrules outlook.rules dim olrule outlook.rule  set olrules = application.session.defaultstore.getrules set olrule = olrules.item("testrule")  debug.print typename(olrule)  printarray olrule.conditions.body.text printarray olrule.conditions.messageheader.text  end sub 

printarray subroutine

private sub printarray(byref parr variant)     dim readstring variant      if (isarray(parr))             'check if passed variable array          each readstring in parr              if typename(readstring) = "string" 'check if readstring string variable                 debug.print readstring             end if          next      end if  end sub 

you integrate second subroutine in first better coding practice perform repetative tasks either in function or in separate subroutine (you use other methods in same module :-))

trust provide solution !

goodluck !


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -