Using word vba to format parts of table cell text -
i'm using following code combine text 2 excel cells word table cell. want format first part (captionstr) bold can't seem figure out how specify part of range.
i tried .range(0,len(captionstr)).font.bold=true
, .range.characters(0,len(captionstr)).font.bold=true
both give me "wrong number of argument" errors. i'm using office 2010 ms word 14.0 object reference
with tbl.cell(nrow, 2).range .style = rfpdoc.styles(wdstylenormal) captionstr = cstr(nsection) + ". " + activecell.text bodystr = activecell.offset(0, 1).text .text = captionstr .range.insertparagraphafter .range.insertafter(bodystr) end
the trick use range object, rather refer entire cell range when writing information. gives finer control on formatting, go. formatting apply current content of range. more like
dim rngcell word.range set rngcell = tbl.cell(nrow, 2).range rngcell 'go cell, rather entire cell .collapse wdcollapsestart 'other stuff .text = captionstr & vbcr .font.bold = true 'move end of range .collapse wdcollapseend 'doing in table cell moves next cell, 1 .moveend wdcharacter, -1 'now rest of content .text = bodystr .font.bold = false end
think of range selection, , collapsing using left-/right arrow key "collapse" selection point.
Comments
Post a Comment