Adjusting Font for Different Sections of Same Paragraph - Excel VBA -
i feeding data word doc excel via vba. want format following.
1. service ticket# 452345: lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua.
the service ticket part bold , italicized , description italicized only. service ticket number , description come different cells in excel.
here's code:
'' bookmark inserting data. wdapp.selection.goto what:=-1, name:="service_ticket_comments" dim integer dim serviceticket string = 4 shaudittrail.range("a4").end(xldown).row '' pulling comments comments column. if not isempty(cells(i, 11)) serviceticket = "service ticket #" & cells(i, 1) wdapp.selection.typetext "service ticket #" & cells(i, 1) wdapp.selection.font.bold = true wdapp.selection.font.italic = true wdapp.selection.typetext " - " & cells(i, 11) & chr(10) & chr(10) wdapp.selection.font.italic = true end if next
this makes service ticket part , description bold , italized because selection applied whole piece. how keep first part bold , italicized , other part bold?
don't work selection
, instead, work range
, same in excel.
it's not clear selection in target word document comes from, have no choice in using starting point. you'd use technique if target chosen user...
dim rng word.range set rng = wdapp.selection.range rng.text = serviceticket rng.font.bold = true rng.font.italic = true rng.collapse wdcollapseend rng.text = cells(i,11) & vbcr rng.font.bold = false rng.font.italic = true
note: should create / use character styles formatting, rather applying formatting directly. results in more efficent code , more manageable document.
Comments
Post a Comment