VBA in Word: Programmatically add content control with a style -


when programatically adding rich text content control word .docm using vba, there way set style contents?

as comparison, if create content control manually using word developer toolbar, can select "use style format contents" in properties dialog content control. result want same if did way, except need in code.

here's code have adds content control, it's triggered command button click few other things well:

private sub selconcept_click()      activedocument.inlineshapes(1).delete     activedocument.inlineshapes(3).delete     activedocument.inlineshapes(3).delete      dim occ contentcontrol     set occ = activedocument.contentcontrols.add(wdcontentcontrolrichtext, _               selection.range)     occ.setplaceholdertext , , "my placeholder text here."     occ.title = "concept" end sub 

if created style, can assign this:

occ.defaulttextstyle = "style_name" 

now, if not, you'll have add style first. like:

activedocument.styles.add name:="mystyle1", type:=wdstyletypecharacter activedocument.styles("mystyle1").font     .name = "arial"     .size = 12     .bold = true     .color = rgb(255, 0, 0) 'you can use rgb here end  occ.defaulttextstyle = "mystyle1" 

Comments

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -