Word VBA - insert more than one type of text -
to all,
i trying automate word document. want insert text. normal code use (for header) is:
selection.typetext text:="this text" selection.style = activedocument.styles("heading 1")  however, want add multiple lines of different styles. so, have following code:
sub createtest()             insertheading1 ("this heading 1")     insertheading2 ("this subheading 1") end sub  function insertheading1(text1)     selection.typetext text:=text1 & chr(11)     selection.style = activedocument.styles("heading 1") end function  function insertheading2(text1)     selection.typetext text:=text1 & chr(11)     selection.style = activedocument.styles("heading 2") end function so, intention add 1 line heading 1 , second line heading 2 (a subheading). happens second bit changes first line both of heading 2 style.
can help? thanks.
try this, me, word 2010 that's right. have add paragraph.
function insertheading1(text1)     selection.typetext text:=text1     selection.style = activedocument.styles(wdstyleheading1)     selection.typeparagraph end function  function insertheading2(text1)     selection.typetext text:=text1     selection.style = activedocument.styles(wdstyleheading2) end function 
Comments
Post a Comment