Different styles within the same Word Table cell using VBA -
i have xls word document automation project 2 strings string1
, string2
needs assigned word table cell. challenge have string1 in red italics font style , string2 in black normal font style. how achieve ?
my present code makes text red itallic, default table font style.
with wdoc.tables(pos) .rows(1).cells(1).range.text = string1 wapp.selection.font.italic = false wapp.selection.font.color = wdcolorautomatic .rows(1).cells(1).range.text = .rows(1).cells(1).range.text & string2 end
the first idea think of use references range based on position of text within whole document. below code find values of 2 properties: .start
, .end
of cell text, check length of both string1
, string2
texts. used document.range(start,end)
parameters. so, code follows (add after code:
with wdoc.tables(pos).rows(1).cells(1).range wdoc.range(.start, .start + len(string1)).font .italic = true .color = vbred end wdoc.range(.end - len(string2), .end).font 'do nothing assuming text black/standard 'or change black if necessary end end
Comments
Post a Comment